Hi,
With pandas 0.17.1 I used to do the following:
import pandas as pd
df = pd.DataFrame(
{'device': ['A', 'A', 'A', 'B', 'B', 'B'],
'timestamp': [0, 2, 4, 1, 3, 5]})
df['start'] = df.groupby('device')['timestamp'].nth(0)
It gave:
df
device timestamp start
0 A 0 0
1 A 2 NaN
2 A 4 NaN
3 B 1 1
4 B 3 NaN
5 B 5 NaN
With pandas 0.18.1, this is what I get:
df
device timestamp start
0 A 0 NaN
1 A 2 NaN
2 A 4 NaN
3 B 1 NaN
4 B 3 NaN
5 B 5 NaN
In pandas 0.17.1, df.groupby('device')['timestamp'].nth(0) returns the index and timestamp column:
But in pandas 0.18.1, it returns the device and timestamp column. The index is "lost":
Is this the new normal behavior?
How can I achieve the same thing as what I was doing in pandas 0.17.1?
My DataFrame is sorted by device and timestamp and I want to get the first (and last) timestamp for each device.
Thanks
Benjamin