I have been searching a lot but could not find an answer to my problem.
I have solar cells measurement data. The data has a timestamp value but no frequency. The number of values in an hour is not constant. Any number of values can occur in an hour. So i am struggling to create:
i. A column with Hourly averages of the data.
ii. Another column that holds number of counts of measurements that occured in each hour. This is important since my timestamp has no fix frequency. So it is important to know whether the mean calculated for a particular hour of the day has 1 or 2 or 14 measurements for example.
My dataframe image:
My code:
yr=df.index.year
mon=df.index.month
day= df.index.day
hr = df.index.hour
df.groupby([yr, mon, day, hr])['KP_sensor'].mean()
How do i add two columns at the end of this dataframe (Mean column and Number of counts of measurements occured in that hour).