1

I made a pivot dataframe at pandas and it's columns are separated in two levels How can I remove the first level?

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
% matplotlib inline
df=pd.read_csv('file01.csv')
grouped_df=df.groupby(['neighborhood','bedrooms'],as_index= False).mean().round()
pivot_df=grouped_df.pivot(index='bedrooms',columns='neighborhood')
pivot_df.columns

the result

MultiIndex(levels=[['price'], ['ANDON', 'ANTIBES', 'ASCROS', 'ASPREMONT', 'AURIBEAU-SUR-SIAGNE']])

I want to remove ['price'] because when I want to filter the picot_dataframe it shows this error

pivot_df['ANDON','ANTIBES']

the error

KeyError: ('ANDON', 'ANTIBES')
Reza energy
  • 135
  • 7

0 Answers0