I have the following tab delimited file (mydata.txt
):
Set Coolthing Route Organ Up Down
set4 foo ID LN 81 60
set4 bar ID LN 542 92
set4 foo ID LV 73 73
set4 bar ID LV 143 78
set4 foo ID SP 32 82
set4 bar ID SP 90 129
And with the following code:
import pandas as pd
df = pd.io.parsers.read_table("http://dpaste.com/3ZTTVQH.txt")
df = df.pivot(index="Coolthing",columns="Organ")
df.drop('Set',axis=1,inplace=True)
df.drop('Route',axis=1,inplace=True)
I have the following data frame:
In [15]: df
Out[15]:
Up Down
Organ LN LV SP LN LV SP
Coolthing
bar 542 143 90 92 78 129
foo 81 73 32 60 73 82
Then using df.to_html(index=True, justify="left")
create this html:
What I want to do is to remove the index names Organ
and Coolthing
. Resulting this:
Up Down
LN LV SP LN LV SP
bar 542 143 90 92 78 129
foo 81 73 32 60 73 82
How can I achieve that?
The most straightforward way to drop a Pandas dataframe index is to use the Pandas . reset_index() method. By default, the method will only reset the index, forcing values from 0 - len(df)-1 as the index. The method will also simply insert the dataframe index into a column in the dataframe.
The drop() function is used to drop specified labels from rows or columns. Remove rows or columns by specifying label names and corresponding axis, or by specifying directly index or column names.
DataFrame has a method called drop() that removes rows or columns according to specify column(label) names and corresponding axis.
There is a name
for single level names and names
for multi-level names so for your example you need to do this to clear the names from index and columns:
In [372]:
df.index.name = None
df.columns.names = (None,None)
df
Out[372]:
Up Down
LN LV SP LN LV SP
bar 542 143 90 92 78 129
foo 81 73 32 60 73 82
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With