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


Picture showing then output when two dataframes are added in pandas
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Thursday, April 18, 2019

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250