当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