I would like to print the output of the following for loop to a nice looking pandas dataframe:
for i in range (1911, 2020):
bestmovie= movie.loc[movie['year'] == i]
bestmovie = bestmovie[['year','title', 'avg_vote', 'genre']].sort_values(['avg_vote'], ascending = False)
bestmovie = bestmovie.head(10)
print (bestmovie)
The output looks like this:
year title avg_vote genre
3 1911 L'Inferno 7.0 Adventure, Drama, Fantasy
38007 1911 Karadjordje 6.3 Drama, War
34547 1911 Oborona Sevastopolya 6.0 History, War
1 1911 Den sorte drøm 5.9 Drama
year title avg_vote \
40716 1912 Le mystère des roches de Kador 7.0
7 1912 Independenta Romaniei 6.7
4 1912 From the Manger to the Cross; or, Jesus of Naz... 5.7
8 1912 Richard III 5.5
2 1912 Cleopatra 5.2
genre
40716 Crime, Drama, Mystery
7 History, War
4 Biography, Drama
8 Drama
2 Drama, History
How can I change it to pandas dataframe format?