【发布时间】:2020-06-24 05:46:27
【问题描述】:
我有一个包含类似格式数据的数据框
song lyric tokenized_lyrics
0 Song 1 Look at her face, it's a wonderful face [look , at , her ,face, it's a wonderful, face ]
1 Song 2 Some lyrics of the song taken [Some, lyrics ,of, the, song, taken]
我想计算每首歌曲歌词中的单词数以及类似
的输出song count
song 1 8
song 2 6
我尝试了聚合函数,但它没有产生正确的结果。
我试过的代码:
df.groupby(['song']).agg(
word_count = pd.NamedAgg(column='text' , aggfunc = 'count' )
)
我怎样才能达到预期的效果
【问题讨论】:
标签: python pandas numpy pandas-groupby