Sequential Within-group Enumeration In Pandas
Say I have the following dataframe: date A B C D 0 2014-03-20 -1.561714 0.979202 -0.454935 -0.629215 1 2014-03-20 0.390851 0.04
Solution 1:
df['date_indexer'] = df.groupby('date').cumcount()
N.B. This is a relatively new addition to pandas (v0.12 or 0.13, I think) so it will not work if you are running an old version.
Post a Comment for "Sequential Within-group Enumeration In Pandas"