I have the following DataFrame:
d= np.array([['Politics', 'Subjectivity', 940, 0.255482, 0.0, 1.0, 0.305992, 0.0, 0.066667, 0.50],
['Celebrities', 'Subjectivity',1000, 0.328217,0.0,1.0,0.342514,0.0,0.30,0.60],
['Brands', 'Subjectivity',893,0.330043,0.0,1.0,0.305782,0.0,0.361111,0.516667],
['Politics', 'Polarity', 940,0.115221,-0.60,1.0,0.241212,0.0,0.0,0.179762],
['Celebrities','Polarity', 1000, 0.160973,-0.90,1.0,0.292662,0.0,0.0,0.343497],
['Brands', 'Polarity', 893,0.130013,-1.0,1.0,0.242577,0.0,0.0,0.267929]])
df= pd.DataFrame(data=d,
columns=pd.Index(['Category','Metric','Count','Mean','Min','Max','STD','25%','50%','75%']))
df
I would like to break down the results in the dataframe by Metric and Category. I tried making a pivot_table()
but I got a key error and then an aggregate error.
df.pivot_table(df['Metric'])
df.pivot_table([['Metric','Category']])
Neither of these lines of code worked. Also, I am not trying to aggregate any data. I would just like to break down the data in the table so it is categorized by metric, then the category. Not sure whether a pivot table or df is best for that.