I have a pandas dataframe in the following format that I would like to reduce.
Index CITY YEAR MONTH HOUR TEMP DP CC ASTR BSTR 2018-04-10 00:00:00 AAA 2018 4 1 20 10 0 hd pv 2018-04-10 01:00:00 AAA 2018 4 2 10 10 10 fg pv ... 2018-04-10 00:00:00 BBB 2018 4 1 30 20 5 cv er 2018-04-10 01:00:00 BBB 2018 4 2 20 20 5 hd fd ... 2018-04-10 00:00:00 CCC 2018 4 1 20 30 10 cv fd 2018-04-10 01:00:00 CCC 2018 4 2 10 10 5 df ee ...
Then the output should be something like:
Index YEAR MONTH HOUR TEMP DP CC ASTR BSTR 2018-04-10 00:00:00 2018 4 1 24 20 5 cv er 2018-04-10 01:00:00 2018 4 2 14 14 6.5 hd fd ...
Where the TEMP, DP, and CC columns are a weighted average of each CITY's value for each unique index (the index is a datetime), and ASTR and BSTR is just the value of BBB. YEAR, MONTH, and HOUR should stay the same. The weights for the above example could be given by the following dictionary: weights = {"AAA" : 0.3, "BBB" : 0.4, "CCC" : 0.3}
My actual data has over 4 years worth of hourly data for multiple cities, so I would like some help coming up with an efficient solution, thanks!