Aug 22, 2017 · 1 min read
Hi Shir,
Thanks for the article.
I think there might be a typo in section 3, 2nd method to achieve the time diff. Since the sorting and shift are applied, is the groupby name required in the second command?
df = df.sort_values(by=['name','timestamp'])
df['time_diff'] = df.groupby('name')['timestamp'].diff()
df.loc[df.name != df.name.shift(), 'time_diff'] = None