yehaita

当pandas从excel文件中读取数值型字符串时,以0开始的字符串有可能将开始的0丢失,造成读取的字符串不完整,如在读取‘000001’时,得到的结果是’1‘。

 

 

为了完整的读出整个字符串,在使用pd.read_excel时需要用到dtype这个参数:

rdSheet = pd.read_excel(\'tmp.xlsx\', dtype = { \'公司代码\' : str })

0    000001
1    000002
2    000004
3    000005
4    000006
5    000007
6    000008
7    000009
8    000010

read_excel()详细参数请参考:

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_excel.html

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-03-11
  • 2021-10-05
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2022-02-08
猜你喜欢
  • 2021-05-17
  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案