I have several dataframes spanning from 2015/09 - 2021/12 as
and each dataframe looks like this
address balance
0 0xb794f5ea0 7504999.894348815
1 0xab7c74abc 1000000.004137971
2 0xdec042a90 5461102.0
3 0xd24400ae8 352884.012859933
4 0x2910543af 217051.397233717
5 0xcafb10ee6 211851.993504593
6 0x167a9333b 164052.961890484
7 0x32be343b9 113179.682105883
8 0xfbb1b73c4 69408.795824975
9 0x7180eb39a 3012.654675749
10 0x0a869d79a 85.171503551
11 0x61edcdf5b 5.0
12 0x2903cadbe 0.985099383
13 0xdd51f01d9 0.002366924
.. .... ....
I want to calculate, let's say, the sum of all balance per date and consolidate into one dataframe as
date balance_sum
2015-09-31 xx
2015-12-31 xx
2016-03-31 xx
...
2021-12-31 xx
Is there a way to do this operation? Thanks a lot in advance!
CodePudding user response:
Here I'm running a for loop over all the dataframes, appending the sum to a list and then creating a dictionary with date as keys and sum as values, finally I'm converting dict to DataFrame.
balance_sum = []
for i in [exchanges_2015_09, exchanges_2015_09 ....]:
balance_sum.append(i['balance_sum'].sum())
data = dict(zip(pd.date_range('2015-09-30', periods=26, freq='Q'), balance_sum))
df = pd.DataFrame(data)