简体   繁体   English

将前导0添加到数据框中的数据列

[英]Add leading 0 to column of data in data frame

Existing data in data frame has dropped leading zero which is required as a part number. 数据帧中的现有数据已下降,前导零是零件号所需的。 The number stored, needs to be 8 digits long and now they vary based on the removal of the leading 0's 存储的数字长度必须为8位,现在根据前导0的去除而有所不同

Sorry I am new to Python and this may be built in function in Pandas but I have not found a way to convert this type of formatting. 抱歉,我是Python的新手,这可能是Pandas中的内置函数,但是我还没有找到转换这种格式的方法。 I have over 2000 part numbers to convert over all 我有2000多个零件号可以转换成全部

EG: 例如:

Part No
9069
38661
90705
9070
907
970206

Part number needs to be: 零件号必须为:

Part No
00009069
00038661
00090705
00009070
00000907
00970206

在使用astype之前,请使用zfill ,如下所示:

df['Part'].astype(str).str.zfill(8)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM