pythanaconda
pythanaconda

Reputation: 183

delete second row of pandas MultiIndex?

I have been trying everything: reset index, etc.

The first level of my row index is a list of dates and the second level is simply [1,1,1,1,1,1,1]. I need to delete the second row index as it is causing problems with plot format.

Upvotes: 0

Views: 2042

Answers (1)

JAB
JAB

Reputation: 12801

you can use droplevel():

from numpy.random import randn
import pandas as pd
arrays = [['bar', 'bar', 'baz', 'baz'],['one', 'three', 'one', 'six',]]
tuples = list(zip(*arrays))
df = pd.DataFrame(randn(10, 4),columns = pd.MultiIndex.from_tuples(tuples, names=['foo', 'bar']))

like this:

df.columns = df.columns.droplevel(1)

or for rows:

df.index = df.index.droplevel(1)

Upvotes: 2

Related Questions