Joining Two DataFrames

Write a Pandas program to join the two given dataframes along rows and assign all data.

Example 1:

Input: DataFrame1, DataFrame2 
Output: Joined DataFrame

Example 2:

Input: DataFrame1, DataFrame2 
Output: Joined DataFrame

Use pandas concat function to join two dataframes along rows.

import pandas as pd

def join_dfs(df1, df2):
    return pd.concat([df1, df2])

df1 = pd.DataFrame({'name': ['Tom', 'Jack', 'Steve', 'Ricky'], 'score': [85, 90, 87, 91]})
df2 = pd.DataFrame({'name': ['Adam', 'Eve', 'Stark', 'Rogers'], 'score': [88, 92, 95, 97]})

print(join_dfs(df1, df2))

 

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!