Difference between revisions of "Iloc"
Jump to navigation
Jump to search
(Created page with "Find the latest value per ID for a dataframe like this: {| class="wikitable" style="width:60%" |- !Index !ID !date !value |- |0 |1 |2019-06-14 23:00:03 |7550.00 |- |0 |2 |201...") |
m |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | Find the latest value per ID for a dataframe like this | + | Function for a [[Pandas#DataFrame]] locating an index(row) |
+ | |||
+ | ;Find the latest value per ID for a dataframe like this | ||
{| class="wikitable" style="width:60%" | {| class="wikitable" style="width:60%" | ||
Line 13: | Line 15: | ||
|7550.00 | |7550.00 | ||
|- | |- | ||
− | | | + | |1 |
− | | | + | |1 |
|2019-06-15 00:00:03 | |2019-06-15 00:00:03 | ||
|7690.00 | |7690.00 | ||
Line 30: | Line 32: | ||
|} | |} | ||
− | <code> | + | <code>df.groupby('ID').apply(lambda d: d.iloc[-1])</code> |
Latest revision as of 16:19, 30 December 2019
Function for a Pandas#DataFrame locating an index(row)
- Find the latest value per ID for a dataframe like this
Index | ID | date | value |
---|---|---|---|
0 | 1 | 2019-06-14 23:00:03 | 7550.00 |
1 | 1 | 2019-06-15 00:00:03 | 7690.00 |
23560 | 17 | 2019-12-15 18:10:43 | 25.50 |
23561 | 17 | 2019-12-16 18:10:45 | 25.52 |
df.groupby('ID').apply(lambda d: d.iloc[-1])