當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