简体   繁体   English

熊猫重命名列名

[英]pandas rename column name

I have the following code: buckets = pd.DataFrame(sample.score.unique()) 我有以下代码: buckets = pd.DataFrame(sample.score.unique())

Which produces: 产生:

        0
0   0.342
1   0.408
2   0.450
3   0.458
4   0.492
5   0.500

When I try to rename the column with buckets.rename(columns = {'0': 'score'}, inplace = True) the column name 0 is not renamed to score . 当我尝试使用buckets.rename(columns = {'0': 'score'}, inplace = True)重命名列时,列名0没有重命名为score

How can rename 0 to score ? 如何重命名0score

就您而言,只需删除列名上的引号

{0: 'scores'}

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

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