How to reset row value in pandas - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to reset row value in pandas (/thread-29776.html) |
How to reset row value in pandas - Mekala - Sep-19-2020 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 1Now 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. |