I am new to pandas, I am getting a result in reverse order of my expected result.
What I have tried is:
o_rg,o_gg,a_rg,a_gg are arrays
df1=pd.DataFrame({'RED':o_rg,'GREEN':o_gg})
df2=pd.DataFrame({'RED':a_rg,'RED':a_gg})
df=df1-(df2)
print(df)
pop_complete = pd.concat([df.T,
df1.T,
df2.T],
keys=["O-A", "O", "A"])
df = pop_complete.swaplevel()
df.sort_index(inplace=True)
print(df)
df.to_csv("OUT.CSV")
What I get the output as:
0 1 2
RED A 14.0 12.0 15.0
O 14.0 12.0 15.0
O-A 0.00 0.00 0.00
GREEN A 12.0 10.0 12.0
O 14.0 9.0 12.0
O-A -2.0 1.0 0.0
What I actually want is:
RED GREEN
A1 O 14.0 14.0
A 14.0 12.0
O-A 0.0 2.0
A3 O 12.0 9.0
A 12.0 10.0
O-A 0.0 -1.0
A8 O 15.0 12.0
A 15.0 12.0
O-A 0.0 0.0
where 'A1','A3','A8' ... can be stored in array cases=[]
How to get the actual output?