I have a pandas dataframe df1
as shown below:
It shows exports volume from A to B, B to A and A to C in three rows. Trade is possible in both directions.
df1.to_dict()
份退货
{‘Country1’:{0:‘a’,1:‘B’,2:‘a’},‘Country2’:{0:‘B’,1:‘a’, 2:‘C’},‘Value’:{0:3,1:5,2:3}}
I want a second dataframe df2
based on df1
which shows the net trade volume between countries.
For example, A to C has a net trade volume of 3 units, and B to A has a net trade volume of 2 units (5-3). This needs to be reflected in the second dataframe as shown below:
如何在df1
的基础上自动创建df2
?
我有大量的国家/地区,所以我想让这个过程自动化.