无法读取excel中的前导零

2024-09-28 22:22:23 发布

您现在位置:Python中文网/ 问答频道 /正文

如果我读excel,它读作

   SKU Code Location Code  GIT
    123456           100   10
    123456           200   20
    123456           300    0

但实际上我的excel数据是

   SKU Code Location Code  GIT
    123456           0100   10
    123456           0200   20
    123456           0300    0

我试过下面的方法

gitDataDF = pd.read_excel("filename.xlsx",
                           sheet_name='Sheet1', inferSchema='true'
                          ,converters={'Location Code': str})

gitDataDF = pd.read_excel("filename.xlsx",
                           sheet_name='Sheet1', inferSchema='true'
                          ,dtype={'Location Code': np.str})

更新1: 值的长度不是固定的。可能是

我该怎么做才能读得像现在这样。你能帮我解决这个问题吗

请参考我使用的Python版本-3.8

熊猫版本-1.0.5


Tags: namegittruereadcodelocationfilenamexlsx