I have a dataframe with information about movies. I'm interested in the columns "Production Company" and "Award". I had to group the dataframe by companies and calculate the number of awards received for them, and then display the three companies with the most value. I did this and got a series:
mv['Award'] = mv['Award'].astype('string')
mv['Winners'] = mv['Award'] == 'Winner'
mv['Winners']=mv['Winners'].astype('string')
mv['Winners'] = mv['Winners'].str.replace('False','')
mv['Winners'] = mv['Winners'].notnull()
mv['Winners']=mv['Winners'].astype('string')
mv['Winners']=mv['Winners'].str.replace('True','Oscar')
Number_Award = mv.groupby(['Production Company'])['Winners'].value_counts().sort_values(ascending = False).head(3)
print(Number_Award)
**Result:**
Production Company Winners
Paramount Pictures Oscar 33
Warner Bros. Pictures Oscar 29
MGM Home Entertainment Oscar 28
Name: Winners, dtype: int64
Then I tried to convert to a dataframe and assign names to the columns, but I could not do this, since there was only one column with the name "Winners". It looked like this:
Number_Award = Number_Award.to_frame()
Number_Award
**Result:**
Winners
Production Company Winners
Paramount Pictures Oscar 33
Warner Bros. Pictures Oscar 29
MGM Home Entertainment Oscar 28
How do I remake the dataframe so it looks something like this:
Production Company Award Number of award
Paramount Pictures Oscar 33
Warner Bros. Pictures Oscar 29
MGM Home Entertainment Oscar 28