Python Pandas velocity -
i have dataframe, first column when customer entered theater , second column name.
time name 1 2 3 4 b 5 b 6 c 7 b 8 c
i want average time customer entry (ignore fact customer has leave in order enter again).
i trying group data frame
df.groupby(['name']).agg({'time' : my_function()})
where
def my_function(): j in range(1,len(time)): total = total + time[j] - time[i] = + 1 return total / (len(time)-1)
i think trying take average difference in times:
in [11]: g = df.groupby('name') in [12]: g['time'].apply(lambda x: x.diff().mean()) out[12]: name 1.0 b 1.5 c 2.0 name: time, dtype: float64
edit: i'm not sure whether want or mean:
in [13]: g['time'].mean() out[13]: name 2.000000 b 5.333333 c 7.000000 name: time, dtype: float64
Comments
Post a Comment