Articles → PANDAS → Add 2 Dataframes In Pandas
Add 2 Dataframes In Pandas
Code
import numpy as np
import pandas as pd
# Creating 2 dataframes
df1 = pd.DataFrame(np.random.randn(5, 4), ['A', 'B', 'C', 'D', 'E'], ['W', 'X', 'Y', 'Z'])
df2 = pd.DataFrame(np.random.randn(5, 4), ['A', 'B', 'C', 'D', 'E'], ['W', 'X', 'Y', 'Z'])
# Printing dataframes
print("First dataframe\n", df1)
print("\nSecond dataframe\n", df2)
# Adding 2 dataframes
df3 = df1 + df2
# Printing resultant dataframe.
print("\nThird dataframe\n", df3)
Output
Click to Enlarge