I have a dataframe with id columns (site_id,type_id,equipment_id), a timestamp and a value as below.
>>>print(df.head())
site_id type_id equipment_id timestamp value
47 9 332859965468 2018-07-04 10:30:04.052000+10:00 23.000000
47 9 332859965468 2018-07-04 10:30:04.064000+10:00 22.050505
47 9 332859965468 2018-07-04 10:30:04.090000+10:00 26.046154
47 9 332859965468 2018-07-04 10:30:04.101000+10:00 22.000000
47 9 332859965468 2018-07-04 10:30:04.113000+10:00 191.989868
I'm trying to resample within each (site_id,type_id,equipment_id) group using the following code
>>> df = df \
... .set_index(['timestamp']) \
... .sort_values(['site_id','type_id','equipment_id','timestamp']) \
... .groupby(['site_id','type_id','equipment_id']) \
... .resample('15T') \
... .mean()
I'm getting unexpected results, all of the id values from the index have been duplicated. It seems to be using the dtype rather than whether the column is in the index or not to perform the aggregation? Am I doning something wrong?
site_id type_id equipment_id value
site_id type_id equipment_id timestamp
47 9 332859965468 2018-07-04 10:30:00+10:00 47.0 9.0 3.328600e+11 58.718625
2018-07-04 10:45:00+10:00 47.0 9.0 3.328600e+11 59.175833
2018-07-04 11:00:00+10:00 47.0 9.0 3.328600e+11 59.238318
2018-07-04 11:15:00+10:00 47.0 9.0 3.328600e+11 58.982763
Edit: I've noticed adding .reset_index(drop=True) removes the duplicate columns - but the issue now is the integer id columns have been converted to floats?