Combine Two DataFrames by Alternating the Rows

By Hemanta Sundaray on 2021-08-31

First, let’s read two Excel worksheets into two different Dataframes:

import pandas as pd

df1 = pd.read_excel('budget.xlsx')

df2 = pd.read_excel('budget.xlsx', sheet_name="Sheet2")

df1.head()

Output:

First Dataframe

df2.head()

Output:

Second Dataframe

Next, we will combine both the Dataframes by alternating the rows:

df3 = pd.concat([df1, df2]).sort_index()

df3.head()

Output Combined Dataframe

Join the Newsletter