21
编辑日期: 2024-11-28 文章阅读: 次
小技巧21:如何使用 count 统计词条出现次数?
读入 IMDB-Movie-Data 数据集,1000行数据:
df = pd.read_csv("../input/imdb-data/IMDB-Movie-Data.csv")
df['Title']
打印 Title
列:
0 Guardians of the Galaxy
1 Prometheus
2 Split
3 Sing
4 Suicide Squad
...
995 Secret in Their Eyes
996 Hostel: Part II
997 Step Up 2: The Streets
998 Search Party
999 Nine Lives
Name: Title, Length: 1000, dtype: object
标题是由几个单词组成,用空格分隔。
df["words_count"] = df["Title"].str.count(" ") + 1
df[["Title","words_count"]]