2
我有数据帧熊猫:日期之间的计数值差值
ID date
111 11-11-2016
111 14-11-2016
111 17-11-2016
222 24-11-2016
222 27-11-2016
我需要统计数据之间的差异,以每一个ID。 我使用
df['duration'] = df.groupby(['ID','date']).date.apply(lambda x: x - x.iloc[0])
idx = df.groupby(['ID'])['duration'].transform(max) == df['count date']
但它返回错误的结果。 我如何获得理想? 我需要
ID count date
111 6
222 3