我在寻找一种优雅的方法来更改DataFrame
中指定的列名。
播放数据。。。
import pandas as pd
d = {
'one': [1, 2, 3, 4, 5],
'two': [9, 8, 7, 6, 5],
'three': ['a', 'b', 'c', 'd', 'e']
}
df = pd.DataFrame(d)
迄今为止我找到的最优雅的解决方案。。。
names = df.columns.tolist()
names[names.index('two')] = 'new_name'
df.columns = names
我希望有一个简单的一行。。。此尝试失败。。。
df.columns[df.columns.tolist().index('one')] = 'another_name'
感激地收到任何暗示。
由于
inplace
参数可用,您不需要复制原始数据帧并将其分配回自身,但请执行以下操作:存在一行:
下面是
rename
方法的docstring。怎么办?
相关问题 更多 >
编程相关推荐