好吧,我检查了问题Remove index name in pandas,但它不适用于我的情况。
所以我有一个df,我用熊猫melt
对其进行了归一化,然后用pivot_table
对它进行了归一化。现在,我有了以下df,但是我想删除此索引名称variable
。
这是df:
df
variable Site Process cap-lo cap-up depreciation ... inv-cost max-grad min-fraction var-cost wacc
0 Mid Biomass plant 0.0 5000.0 25.0 ... 875000.0 1.500000e+15 0.0 1.4 0.07
1 Mid Coal plant 0.0 0.0 40.0 ... 600000.0 1.500000e+15 0.0 0.6 0.07
2 Mid Gas plant 0.0 80000.0 30.0 ... 450000.0 1.500000e+15 0.0 1.6 0.07
3 Mid Hydro plant 0.0 1400.0 50.0 ... 1600000.0 1.500000e+15 0.0 0.0 0.07
4 Mid Lignite plant 0.0 60000.0 40.0 ... 600000.0 1.500000e+15 0.0 0.6 0.07
5 Mid Solar plant 0.0 160000.0 25.0 ... 600000.0 1.500000e+15 0.0 0.0 0.07
6 Mid Wind plant 0.0 13000.0 25.0 ... 1500000.0 1.500000e+15 0.0 0.0 0.07
7 North Biomass plant 0.0 6000.0 25.0 ... 875000.0 1.500000e+15 0.0 1.4 0.07
8 North Coal plant 0.0 100000.0 40.0 ... 600000.0 1.500000e+15 0.0 0.6 0.07
9 North Gas plant 0.0 100000.0 30.0 ... 450000.0 1.500000e+15 0.0 1.6 0.07
10 North Hydro plant 0.0 20000.0 50.0 ... 1600000.0 1.500000e+15 0.0 0.0 0.07
11 North Lignite plant 0.0 0.0 40.0 ... 600000.0 1.500000e+15 0.0 0.6 0.07
12 North Solar plant 0.0 3000.0 25.0 ... 600000.0 1.500000e+15 0.0 0.0 0.07
13 North Wind plant 0.0 60000.0 25.0 ... 1500000.0 1.500000e+15 0.0 0.0 0.07
14 South Biomass plant 0.0 0.0 25.0 ... 875000.0 1.500000e+15 0.0 1.4 0.07
15 South Coal plant 0.0 100000.0 40.0 ... 600000.0 1.500000e+15 0.0 0.6 0.07
16 South Gas plant 0.0 100000.0 30.0 ... 450000.0 1.500000e+15 0.0 1.6 0.07
17 South Hydro plant 0.0 0.0 50.0 ... 1600000.0 1.500000e+15 0.0 0.0 0.07
18 South Lignite plant 0.0 0.0 40.0 ... 600000.0 1.500000e+15 0.0 0.6 0.07
19 South Solar plant 0.0 600000.0 25.0 ... 600000.0 1.500000e+15 0.0 0.0 0.07
20 South Wind plant 0.0 200000.0 25.0 ... 1500000.0 1.500000e+15 0.0 0.0 0.07
我想删除索引上方的variable
。我该怎么办?
它可能不是索引名,而是列名...我只想删除变量。
PS:df.index.name = 'blah'
执行以下操作:
df
variable Site Process cap-lo cap-up depreciation ... inv-cost max-grad min-fraction var-cost wacc
blah ...
0 Mid Biomass plant 0.0 5000.0 25.0 ... 875000.0 1.500000e+15 0.0 1.4 0.07
1 Mid Coal plant 0.0 0.0 40.0 ... 600000.0 1.500000e+15 0.0 0.6 0.07
2 Mid Gas plant 0.0 80000.0 30.0 ... 450000.0 1.500000e+15 0.0 1.6 0.07
3 Mid Hydro plant 0.0 1400.0 50.0 ... 1600000.0 1.500000e+15 0.0 0.0 0.07
4 Mid Lignite plant 0.0 60000.0 40.0 ... 600000.0 1.500000e+15 0.0 0.6 0.07
5 Mid Solar plant 0.0 160000.0 25.0 ... 600000.0 1.500000e+15 0.0 0.0 0.07
6 Mid Wind plant 0.0 13000.0 25.0 ... 1500000.0 1.500000e+15 0.0 0.0 0.07
7 North Biomass plant 0.0 6000.0 25.0 ... 875000.0 1.500000e+15 0.0 1.4 0.07
8 North Coal plant 0.0 100000.0 40.0 ... 600000.0 1.500000e+15 0.0 0.6 0.07
9 North Gas plant 0.0 100000.0 30.0 ... 450000.0 1.500000e+15 0.0 1.6 0.07
10 North Hydro plant 0.0 20000.0 50.0 ... 1600000.0 1.500000e+15 0.0 0.0 0.07
11 North Lignite plant 0.0 0.0 40.0 ... 600000.0 1.500000e+15 0.0 0.6 0.07
12 North Solar plant 0.0 3000.0 25.0 ... 600000.0 1.500000e+15 0.0 0.0 0.07
13 North Wind plant 0.0 60000.0 25.0 ... 1500000.0 1.500000e+15 0.0 0.0 0.07
14 South Biomass plant 0.0 0.0 25.0 ... 875000.0 1.500000e+15 0.0 1.4 0.07
15 South Coal plant 0.0 100000.0 40.0 ... 600000.0 1.500000e+15 0.0 0.6 0.07
16 South Gas plant 0.0 100000.0 30.0 ... 450000.0 1.500000e+15 0.0 1.6 0.07
17 South Hydro plant 0.0 0.0 50.0 ... 1600000.0 1.500000e+15 0.0 0.0 0.07
18 South Lignite plant 0.0 0.0 40.0 ... 600000.0 1.500000e+15 0.0 0.6 0.07
19 South Solar plant 0.0 600000.0 25.0 ... 600000.0 1.500000e+15 0.0 0.0 0.07
20 South Wind plant 0.0 200000.0 25.0 ... 1500000.0 1.500000e+15 0.0 0.0 0.07
答案 0 :(得分:0)
您可以使用rename_axis
:
df = df.rename_axis(None, axis=1)
# df.columns.name = None
# To remove index label
df = df.rename_axis(None, axis=0)
# df.index.name = None