Instagram
youtube
Facebook
Twitter

Concatenate Two Pandas DataFrames Horizontally

A Concatenate Two Pandas DataFrames Horizontally ?
Code Explanation:
● Concatenation: pd.concat() with axis=1 combines DataFrames side-by-side.
● Store Result: Result is stored in df3.
● Output Display: Horizontally concatenated DataFrame is printed.

 

Program:

import pandas as pd

df1 = pd.DataFrame({'ID': [1, 2], 'Name': ['Alice', 'Bob']})

df2 = pd.DataFrame({'ID': [1, 2], 'Score': [90, 95]})

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

print(df3)