3

I'm trying to count the number of unique values in a dataframe column using pandas.Series.explode as I'm not interested in exploding the entire dataframe. The dataframe column I'm trying to explode looks like

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

I tried df.lists.explode().value_counts() which throws an AttributeError: 'Series' object has no attribute 'explode'. The same error is observed while exploding the entire dataframe with df.explode('lists'). I cannot see if it been deprecated so I'm not sure what's wrong when the source examples don't work either.

Vanshika
  • 153
  • 1
  • 3
  • 7
  • ```df.to_frame().explode('lists')``` will do – Grzegorz Skibinski Mar 28 '20 at 12:31
  • What is the version of Pandas package that you are using? in case of multiple environments, and if you are not sure, just print `pandas.__version__` after importing pandas in your python code. Could you please edit your question and add that information to your question? Thank you. – Mitali Cyrus Jun 06 '20 at 17:55

1 Answers1

5

According to the Pandas official documentation about Series.explode(), this function is

New in version 0.25.0.

I think your problem might be because of an older package version. Updating your pandas package might resolve your issue.

Mitali Cyrus
  • 446
  • 4
  • 12