有没有办法将R中变量的名称更改为标签值
例如,当变量表示“年龄段”时,我试图将其更改为“三向分带年龄组”:
Data_2017_18.ageband.value_counts()
Out[118]:
51 to 99 13320
30 to 40 10985
1 to 29 5002
Name: ageband, dtype: int64
我试过这个,但似乎不起作用:
import pandas as pd
Data_2017_18['Three-way banded age group'] = Data_2017_18['ageband'].astype("category")
注意:将列名重命名为包含空格的名称被认为是一种不好的做法,应该使用下划线来避免
要重命名pandas中的列,只需使用^{} 方法
相关问题 更多 >
编程相关推荐