[英]Extending the column name in pandas DataFrame
I have a data frame which contains 34 rows and 10 columns. 我有一个包含34行和10列的数据框。 I called the data frame "comp" now I did "invcomp = 1/comp", So the values changed but column name will be same.
我将数据帧称为“ comp”,现在执行了“ invcomp = 1 / comp”,因此值已更改,但列名将相同。 I want to replace or rename my column names, suppose the earlier name of my first column was "Cbm_m" in "comp", now I want to convert it to "Cbm_m_inv" in "invcomp".
我想替换或重命名我的列名,假设我的第一列的先前名称是“ comp”中的“ Cbm_m”,现在我想将其转换为“ invcomp”中的“ Cbm_m_inv”。 Extending or adding an extra term in last.
最后扩展或添加一个额外的术语。
Use 'add_suffix': 使用'add_suffix':
invcomp = invcomp.add_suffix('_inv')
Setup: 设定:
invcomp = pd.DataFrame(pd.np.random.rand(5,5), columns=list('ABCDE'))
invcomp = invcomp.add_suffix('_inv')
Output: 输出:
A_inv B_inv C_inv D_inv E_inv
0 0.111604 0.016181 0.384071 0.608118 0.944439
1 0.523085 0.139200 0.495815 0.007926 0.183498
2 0.090169 0.357117 0.381938 0.222261 0.788706
3 0.802219 0.002049 0.173157 0.716345 0.182829
4 0.260781 0.376730 0.646595 0.324361 0.345097
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.