我有一个数据帧“genres”,其中列中每行的值用“,”分隔。我需要计算每个值,比如喜剧2,戏剧7等等。努特尝试了许多方法都失败了。在
我尝试了genres = trending.groupby(['genre']).size()
,但这一行将'Comedy,Crime,CriticallyAcclaimed'
视为一个值。我是python新手,请帮帮我。在
genre
Comedy,Crime,CriticallyAcclaimed
Comedy,Drama,Romance
Drama
Drama
Drama,Hollywood
Drama,Romance
Drama,Romance
Drama,Romance,Classic
如果您使用的是
pandas
,那么即使在OP中没有说的内容也可以猜出来,您可以执行类似的操作:下面的代码假设您已经知道一行中的最大项数。这意味着您需要读取该文件一次并找到这些信息(在这里,根据您的示例,我们假设这个数字是3)。在
该代码将文件读入一个dataframe,去掉None值,在dataframe中找到所有惟一的值,并计算它们在dataframe中的出现次数。在
我得到了答案:
相关问题 更多 >
编程相关推荐