问题
DataFrame where Date is datetime:
Column | Date
:-----------|----------------------:
A | 2018-08-05 17:06:01
A | 2018-08-05 17:06:02
A | 2018-08-05 17:06:03
B | 2018-08-05 17:06:07
B | 2018-08-05 17:06:09
B | 2018-08-05 17:06:11
Return Table is;
Column | Date
:-----------|----------------------:
A | 2018-08-05 17:06:02
B | 2018-08-05 17:06:09
回答1:
For your example.
Your data:
df = pd.DataFrame(data=[['A', '2018-08-05 17:06:01'],
['A', '2018-08-05 17:06:02'],
['A', '2018-08-05 17:06:03'],
['B', '2018-08-05 17:06:07'],
['B', '2018-08-05 17:06:09'],
['B', '2018-08-05 17:06:11']],
columns = ['column', 'date'])
Solution:
df.date = pd.to_datetime(df.date).values.astype(np.int64)
df = pd.DataFrame(pd.to_datetime(df.groupby('column').mean().date))
Output:
date
column
A 2018-08-05 17:06:02
B 2018-08-05 17:06:09
I hope it will be helpful.
来源:https://stackoverflow.com/questions/52007139/pandas-datetime-average