Reputation: 1568
Well I checked the question Remove index name in pandas, and it is not working for my case.
So I had a df, I normalized it with pandas melt
, then I denormalize it with pivot_table
. Now I have the following df, but I want to remove this index name variable
.
Here is the 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
I want to remove this variable
which is above the indexes. How would I do that?
It is probably not an index name, but a column name... I just want to remove the variable.
PS: df.index.name = 'blah'
does following:
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
Upvotes: 13
Views: 10791
Reputation: 4233
You can use 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
Upvotes: 22