我想創建一個新列。列應計算同一日期的所有行。
in:
| date |
----------------
| 12.02.2000 |
| 12.02.2000 |
| 12.02.2000 |
| 12.02.2000 |
| 12.02.2000 |
| 13.02.2000 |
| 14.02.2000 |
| 14.02.2000 |
out:
| date | Cumulative
---------------|-----------
| 12.02.2000 | 1
| 12.02.2000 | 2
| 12.02.2000 | 3
| 12.02.2000 | 4
| 12.02.2000 | 5
| 13.02.2000 | 1
| 14.02.2000 | 1
| 14.02.2000 | 2
uj5u.com熱心網友回復:
你想cumcount在一個之后使用groupby
df.assign(Cumulative=df.groupby('date').cumcount() 1)
date Cumulative
0 12.02.2000 1
1 12.02.2000 2
2 12.02.2000 3
3 12.02.2000 4
4 12.02.2000 5
5 13.02.2000 1
6 14.02.2000 1
7 14.02.2000 2
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/456044.html
