0

I have generated a pandas dataframe using below code where an example sequence column is like '0-0-0-1-0-0-2-0-0-0-0' I split the sequence string into different columns

df = DataFrame(data, columns = ['id', 'sequence'])
print(df.sequence.str.split("-", expand=True))

0 1 2 3 4 5 6 7 8 9

0 0 0 0 1 0 0 2 0 0
1 0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0
3 0 1 0 0 2 0 0 0 0
4 0 0 0 3 0 0 0 0 0
5 0 0 0 0 0 4 0 0 0

If I want to count the number of occurences of 0 in each column, how do I do it?

I tried something like this print df[df.education == '9th'].count() based on Python Pandas Counting the Occurrences of a Specific value but I don't have column names appropriately, and I am not sure how to do it.

Can you please help.

Gayatri
  • 152
  • 3
  • 12

1 Answers1

0

Have you tried this?

df.rename(columns={"A": "NewName", "B": "NewName"})
wwii
  • 23,232
  • 7
  • 37
  • 77
  • [Formatting help](https://stackoverflow.com/editing-help#code) ... [more Formatting](https://stackoverflow.com/editing-help) ... [Formatting sandbox](https://meta.stackexchange.com/questions/3122/formatting-sandbox) – wwii May 26 '20 at 02:51