【发布时间】:2020-03-28 12:26:18
【问题描述】:
我正在尝试 count the number of unique values in a dataframe column 使用 pandas.Series.explode 因为我对爆炸整个数据框不感兴趣。 我试图爆炸的数据框列看起来像
df["lists"].head()
0 [cl5, bn6, sp1]
1 [cl5, bn6, sp1]
2 [cl5, bn6, sp1]
3 [bn6, sp1]
4 [bn6, sp1]
Name: lists, dtype: object
我尝试了df.lists.explode().value_counts(),它抛出了一个AttributeError:“Series”对象没有“explode”属性。
在 exploding the entire dataframe 和 df.explode('lists') 时观察到相同的错误。我看不到它是否已被弃用,所以我不确定源示例也不起作用时出了什么问题。
【问题讨论】:
-
df.to_frame().explode('lists')可以 -
您使用的是什么版本的 Pandas 包?在多个环境的情况下,如果您不确定,只需在 python 代码中导入 pandas 后打印
pandas.__version__。您能否编辑您的问题并将该信息添加到您的问题中?谢谢。
标签: python pandas dataframe series