我正在尝试 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' object has没有属性“爆炸”。
exploding the entire dataframe 时观察到相同的错误使用 df.explode('lists')
。我看不到它是否已被弃用,所以我不确定当源示例也不起作用时出了什么问题。
最佳答案
根据Pandas official documentation about Series.explode() , 这个函数是
New in version 0.25.0.
我认为您的问题可能是因为软件包版本较旧。更新您的 pandas 包可能会解决您的问题。
关于python - pandas.Series.explode 抛出 AttributeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60901113/