Skip to content
Advertisement

how to count data in a certain column in python(pandas)?

hope you’re doing well . i tried counting green color row after another green colored row in the table below In [1]: df = pd.DataFrame([[green], [red], [red]], columns=[‘A’])

the code i tried to count greengreen:

JavaScript

but it didn’t work,hope you can help. note: i’m new to data science

Advertisement

Answer

You can use:

JavaScript

As a one-liner (python ≥ 3.8):

JavaScript

example input:

JavaScript

output: 3

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement