Python Forum
How to reset row value in pandas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to reset row value in pandas
#1
Hi,
I have below dataframe:

df
ID   Grp subGrp Rank  SNO
A.1  A.0  A     S      1
A.2  A.0  A     S      1
A.2  A.0  A     N      1
A.6  A.0  A     N      1
A.3  A.0  A     S      1 
A.1  A.B  A     3      1
A.2  A.B  A     3      1
A.4  A.0  A     3      1
A.2  A.0  A     3      1
Now I want to increase SNO by 1 in each row, but reset at each repeating ID(at first repeat row) & same columns "subGrp" &"Rank"

Desired output:

ID Grp subGrp Rank SNO
A.1 A.0 A S 1
A.2 A.0 A S 2
A.2 A.0 A S 1
A.6 A.0 A S 2
A.3 A.0 A S 3
A.1 A.0 A S 1
A.2 A.0 A S 2
A.4 A.0 A S 3
A.2 A.0 A S 1
A.1 A.0 A S 2

A.1 rpeats & A.2 repeats but its coninuouse so not reset at A.2. A.2 rpeats again 8th row, reset and increase by one next row.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Reset a variable mln4python 4 6,636 Aug-19-2019, 08:28 AM
Last Post: mln4python

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020