If I have dataframes,
df1 = pd.DataFrame(
{
"A": ["A0", "A1", "A2", "A3"],
"B": ["B0", "B1", "B2", "B3"],
"C": ["C0", "C1", "C2", "C3"],
"D": ["D0", "D1", "D2", "D3"],
},
index=[0, 1, 2, 3],)
df2 = pd.DataFrame(
{
"A": ["A4", "A5", "A6", "A7"],
"B": ["B4", "B5", "B6", "B7"],
"C": ["C4", "C5", "C6", "C7"],
"D": ["D4", "D5", "D6", "D7"],
},
index=[4,5,6,7],)
I want to use pd.concat to combine these two dataframes as
dfnew = pd.concat([df1.loc[0],
df1.loc[1],
df1.loc[2],
df1.loc[3],
df2.loc[4],
df2.loc[5],
df2.loc[6],
df2.loc[7]],
axis=0,sort=False)
dfnew = dfnew.to_frame().transpose()
dfnew is a 1row x 32 columns dataframe. But how about I have many rows in df1 and df2, or I want to combine different number of rows of df1 and df2 in a loop? What can I do for the concat .loc[] part? Or is there another way to do this?
Thank you ahead.