pandas.Series.explode 抛出 AttributeError

Van*_*ika 3 python series dataframe pandas

我正在尝试使用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
Run Code Online (Sandbox Code Playgroud)

我尝试df.lists.explode().value_counts()抛出一个AttributeError : 'Series' object has no attribute 'explode'。用爆炸整个数据帧时观察到相同的错误df.explode('lists')。我看不到它是否已被弃用,所以当源示例也不起作用时,我不确定有什么问题。

Mit*_*rus 5

根据关于 Series.explode()Pandas 官方文档,这个函数是

0.25.0 版中的新功能。

我认为您的问题可能是由于较旧的软件包版本。更新您的熊猫包可能会解决您的问题。