0

I have a DataFrame with a column named players, I want to count all the players playing in that round for all the rows.

This is how it looks like.

These values- simple5dd1bd72e209cf05624291cd, simple62d6fd3.....

Some of these rows have 3 values some have 4 some have 5. I want to count the number of values one row has. Every one of them is separated by comma (,) and start with simple.

df['PlayersCount'] = df['players'].str.count('simple')

I tried using this but I am getting NaN in PlayersCount Column.

   tags = df2['players'].str.split(',')
   df2['PlayersCount'] = len(tags)

I also tried this but it gives me 20777.

Sorry I could not make a sample dataframe for you guys, as I do not know how to.

enter image description here

Arkam
  • 35
  • 5

1 Answers1

0

IIUC:

df2['PlayersCount'] = df2['players'].str.len()

Or:

df2['PlayersCount'] = df2["Player"].str.count(",") + 1
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252