1

I have the following DataFrame:

data_raw (201 x 600)
Column Level 0: ROE_1 ROE_2 Test_EQ_1
Column Level 1: A B C D E F G H I J .... (200 items)
Index Level 0: 1 2 3 4... (201 items)

I am trying to drop the Test_EQ_1 column.

After using:

data_raw = data_raw.drop("Test_EQ_1", axis=1, level=0)

The dataframe's dimension is reduced to 201x400 (as expected). All columns with Test_EQ_1 are gone (as expected).

However, when I use the following:

data_raw.columns.levels[0]

I obtain:

Index(['ROE_1', 'ROE_2', **'Test_EQ_1'**], dtype='object', name='Variable')

This is generating issues for later parts of my code, as Test_EQ_1 is gone from the dataframe, but still present when I check the columns.

Is there a way to "completely" delete Test_EQ_1?

1 Answer 1

2

Found an answer: Redefine the columns:

    multi = data_raw.columns.to_list()
    data_raw.columns = pd.MultiIndex.from_tuples(multi)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.