Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在pandas中正确导入前缀为00的数字数据?_Python_Pandas_Dataframe - Fatal编程技术网

Python 如何在pandas中正确导入前缀为00的数字数据?

Python 如何在pandas中正确导入前缀为00的数字数据?,python,pandas,dataframe,Python,Pandas,Dataframe,示例我的数据集有00501,00544 作为数据帧导入后,它将变为如下所示 0 501 1 544 Name: VALUE, dtype: int64 假设这是邮政编码,那么nchar应该等于5 df.v.astype(str).str.rjust(5,'0') Out[101]: 0 00501 1 00544 Name: v, dtype: object 使用zfill: df['Col'] = df['Col'].astype(str).st

示例我的数据集有
00501
00544

作为数据帧导入后,它将变为如下所示

    0    501
    1    544

Name: VALUE, dtype: int64

假设这是邮政编码,那么nchar应该等于5

df.v.astype(str).str.rjust(5,'0')
Out[101]: 
0    00501
1    00544
Name: v, dtype: object

使用
zfill

df['Col'] = df['Col'].astype(str).str.zfill(5)

从PyviuOS评论中,如果你从文件<代码>数据.CSV 中读取,在给定列中,你有超前的0,你可以考虑使用

读取它。
df = pd.read_csv("data.csv", dtype="object")

如果重要的话,它是字符串数据,而不是数字数据。