0

I have two dataframes

df1 = pd.read_csv('src_lnd.csv')
df2 = pd.read_csv('lnd_pst.csv')

Their outputs are
df1:

Source Landing Result
120 120 Pass

df2:

Landing Persistence Result
120 120 Pass

I need to write both these dataframes to an excel file such that it looks like
Excel file:

Source Landing Result
120 120 Three
Landing Persistence Result
120 120 Three

So literally just write the dataframes as is row by row. I will also have more dataframes created in the future which I will have to append to the same in a new row. All the data is in one sheet only

1 Answers1

0

You can set the columns for each dataframe as a row and concat the two dataframes together.

# set column names as first row and concat dataframes
final_df = pd.concat([df1.T.reset_index().T, df2.T.reset_index().T], axis=0)

This outputs:

0 1 2
Source Landing Result
120 120 Pass
Landing Persistence Result
120 120 Pass

And you can rename the columns to something more suitable before writing it into the file.

greco
  • 304
  • 4
  • 11