Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to up value in new column, when occur 0?

I have this df:

data = {'Name': ['T', 'J', 'K', 'J', 'M', 'A', 'J', 'K','L', 'o', 'j' ], 'Match': [0,1,2,0,1,0,1,2,3,0,1]}

Df =  pd.DataFrame(data)

I want to apply column, which show season for each match. Season sholud be more then previous every time when match value is 0.
What is important, number of matches in every season is different.

Out sholud be:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

What do you suggest?

>Solution :

df['Season'] = (df['Match']==0).cumsum()

Turn zeros to True (1) and the rest to False (0), and cumulatively sum them, it will increment only when seeing a True

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading