-1

I'm trying to create a new column in a pandas dataframe that shows the total number of items seen in another column comprised of lists like the one in the hashtag and ment column below.

I tried the following but I'm getting an error message.

df['hashcount']=df['hashtag'].value_counts()

enter image description here

Quang Hoang
  • 146,074
  • 10
  • 56
  • 74
rpa1111
  • 13
  • 2
  • 2
    It's kinda strange when read *I tried the following but I'm getting an error message.* and you don't see any error message in the question. That said, `[]` looks like a list and lists are mutable so can't be hashed/compared so no `value_counts()`. – Quang Hoang Oct 17 '20 at 04:12
  • Are you trying to get the value_counts per row within the list OR are you trying to get the value_counts of each unique list within your dataframe? Please see how to ask a pandas question here. Please include input (no images) and desired output (no images): https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples – David Erickson Oct 17 '20 at 04:14

1 Answers1

1

try:

df['hashcount']=df['hashtag'].apply(len)

This will return the number of elements in each list you have in the column 'hashtag'.

annicheez
  • 187
  • 5