• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: pandas increment under specific condition of other column

Resolved: pandas increment under specific condition of other column

0
By Isaac Tonny on 18/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

Given dataframe
how to get result like in column B?
The idea is when column A row is equal with column A previous row, add 1, else back to 0
I’ve tried:
however, the result that i got is [0,0,1,1,1,0] instead
do i missed some steps or non logical operation here?
any hint will be very helpful
thank you in advance

Answer:

Let us try groupby and cumcount:

If you have better answer, please add a comment about this, thank you!

dataframe pandas python
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Getting ‘502 Bad Gateway’ while deploying Springboot app in EKS

24/03/2023

Resolved: Why is NGINX’s $request_uri empty?

24/03/2023

Resolved: How to convert Java bytecode to Webassembly using CheerpJ compiler

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.