I have 3 dataframe in list
import pandas as pd
import numpy as np
data1 = [['A',0],['B',0],['C',1]]
Data1 = pd.DataFrame(data1,columns=['Strategy','Weights'])
data2 = [['A',0],['B',1],['C',0]]
Data2 = pd.DataFrame(data2,columns=['Strategy','Weights'])
data3 = [['A',0],['B',1],['C',0]]
Data3 = pd.DataFrame(data3,columns=['Strategy','Weights'])
AA = []
AA.append(Data1)
AA.append(Data2)
AA.append(Data3)
I want to convert like the following: https://i.stack.imgur.com/rQM6H.png can someone help me finish it? and is there an easier way to do it?thank you very much
use df.concat(<listOfDataframe>)
to combine multiple dataframe. ie
AA = pd.concat([Data1,Data2,Data3],ignore_index=True)
Edit
If you want to make new dataframe, the easier way to define it, IMO, is:
df = {
'A':[0,0,0],
'B':[0,1,0],
'C':[0,1,0]
}
df = pd.DataFrame(df)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.