Importing packages¶
In [1]:
import pandas as pd
In [2]:
cols = pd.MultiIndex.from_tuples([("a", "b"), ("a", "c")])
df = pd.DataFrame([[1,2], [3,4]], columns=cols)
df
Out[2]:
In [3]:
print(df.columns)
In [4]:
# dropping multilevel column index using pandas function
df.columns = df.columns.droplevel()
df
Out[4]:
OR¶
In [5]:
# rewriting columns
df.columns = ['b', 'c']
df
Out[5]: