[英]How to find the average movie rating per year?
嗨所以我目前正在研究看起來像這樣的 IMDB 電影元數據 dataframe。
我需要幫助找到每年平均 imdb 評級。 每個imdb_score
的title_year
。
現在,我計算了每年的電影數量,並減少了少於 10 部電影的年份,以使其具有相關性。
我做了如下
years = df['title_year'].value_counts()
years
接着
years2 = years[years >= 10]
years2
這導致
2009.0 260
2014.0 252
2006.0 239
2013.0 237
2010.0 230
2015.0 226
2011.0 225
2008.0 225
2012.0 221
2005.0 221
2004.0 214
2002.0 209
2007.0 204
2001.0 188
2000.0 171
2003.0 169
1999.0 168
1998.0 134
1997.0 118
2016.0 106
1996.0 99
1995.0 70
1994.0 54
1993.0 48
1992.0 34
1981.0 33
1989.0 33
1987.0 32
1991.0 31
1988.0 31
1984.0 31
1982.0 30
1990.0 30
1985.0 29
1986.0 26
1980.0 24
1983.0 22
1978.0 16
1977.0 16
1979.0 16
1970.0 12
1971.0 11
1968.0 11
1969.0 10
1964.0 10
1976.0 10
Name: title_year, dtype: int64
現在我很困惑你如何找到每年的平均 imdb 評級,因為我想在 plot 之后繪制圖表。 有誰能夠幫我?
您可以使用pandas.DataFrame.groupby :
year_avg_score = df.loc[df['title_year'].isin(year2.index)].groupby('title_year')['imdb_score'].mean()
一步步:
df.loc[df['title_year'].isin(year2.index)]
僅過濾您已經計算過的超過 10 部電影的年份。title_year
和 select 對imdb_score
列進行分組。imdb_score
平均值。 生成的 dataframe year_avg_score
將以年份作為索引,將平均分數作為列。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.