Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.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
Pandas 从值更改索引类型\u counts()_Pandas_Dataframe_Series - Fatal编程技术网

Pandas 从值更改索引类型\u counts()

Pandas 从值更改索引类型\u counts(),pandas,dataframe,series,Pandas,Dataframe,Series,我正在尝试将value\u counts()之后的索引类型从int更改为string 输出: 40.0 1448 45.0 28558 50.0 83675 55.0 96377 60.0 47351 65.0 13226 70.0 2602 75.0 568 80.0 72 100.0 52 105.0 53 Name: value, dtype: int64 预期产出: 40.0

我正在尝试将
value\u counts()之后的索引类型从
int
更改为
string

输出:

40.0      1448
45.0     28558
50.0     83675
55.0     96377
60.0     47351
65.0     13226
70.0      2602
75.0       568
80.0        72
100.0       52
105.0       53
Name: value, dtype: int64
预期产出:

40.0      1448
45.0     28558
50.0     83675
55.0     96377
60.0     47351
65.0     13226
70.0      2602
75.0       568
80.0        72
100.0       52
105.0       53
Name: value, dtype: string

如果需要转换排序后的索引值,如
40.0
,请使用
rename

df['value'].value_counts().sort_index().rename(index=str)
如果需要转换计数值,如
1448
使用:

为什么不添加
.astype(str)
df['value'].value_counts().sort_index().rename(index=str)
df['value'].value_counts().sort_index().astype(str)