I have the following data frame
import pandas as pd
df = pd.DataFrame({ 'gene':["foo",
"lal",
"qux",
"woz"], 'cell1':[5,9,1,7], 'cell2':[12,90,13,87]})
df = df[["gene","cell1","cell2"]]
df
看起来是这样的:
gene cell1 cell2
0 foo 5 12
1 lal 9 90
2 qux 1 13
3 woz 7 87
我想要做的是更改第1列和第3列的列名。 结果如下:
X cell1 Y
foo 5 12
lal 9 90
qux 1 13
woz 7 87
如何使用索引编号 0
和 2
来完成此操作。
我可以做到这一点。
df.columns = ["X","cell1","Y"]
但它不使用列索引。