DataFrames are 2-dimensional data structures in pandas. DataFrames consist of rows, columns, and the data. DataFrame can be created with the help of python dictionaries or lists but in the real world, CSV files are imported and then converted into DataFrames. Sometimes, DataFrames are first written into CSV files. Here, we are going to merge two DataFrames by index, for this purpose we are going to use pandas.DataFrame.merge() method.
pandas.DataFrame.merge() Method
When we want to update a DataFrame with the help of another DataFrame, we use pandas.DataFrame.merge() method. This method is used to merge two DataFrames based on an index.
Syntax:
DataFrame.merge(
right,
how='inner',
on=None,
left_on=None,
right_on=None,
left_index=False,
right_index=False,
sort=False,
suffixes=('_x', '_y'),
copy=True,
indicator=False,
validate=None
)
To work with pandas, we need to import pandas package first, below is the syntax:
import pandas as pd
Let us understand with the help of an example.
Here, we have passed two parameters, left_index and right_index which generally means whether to use the index from left and right DataFrame or not, we want the DataFrames to be merged on the basis of index, hence we will set left and right index as True.
Output:

need an explanation for this answer? contact us directly to get an explanation for this answer