Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.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 设置熊猫中整数列的格式_Python_Pandas_Dataframe_Formatting - Fatal编程技术网

Python 设置熊猫中整数列的格式

Python 设置熊猫中整数列的格式,python,pandas,dataframe,formatting,Python,Pandas,Dataframe,Formatting,我想先将这列整数转换为字符串,然后用两个有效数字格式化每个单位数整数 我想要这个: >>> df[0].astype(str) 0 0 1 1 2 2 3 10 4 11 5 12 为此: >>> df[0].astype(str) 0 00 1 01 2 02 3 10 4

我想先将这列整数转换为字符串,然后用两个有效数字格式化每个单位数整数

我想要这个:

>>> df[0].astype(str)
0          0
1          1
2          2
3          10
4          11
5          12
为此:

>>> df[0].astype(str)
0          00
1          01
2          02
3          10
4          11
5          12
通常我会使用
%.2d
,但我不确定如何使用熊猫?

使用

通过在“0”字符前加前缀来填充序列/索引中的字符串


使用

通过在“0”字符前加前缀来填充序列/索引中的字符串


df[0].astype(str).str.zfill(2)
0    00
1    01
2    02
3    10
4    11
5    12