Combine pandas DataFrames with Different Column Names in Python | How to Apply the concat() Function

preview_player
Показать описание
Python code of this video:

import pandas as pd # Import pandas library in Python

data1 = pd.DataFrame({"col1":["a", "b", "c", "d"], # Create first pandas DataFrame
"col2":range(4, 0, - 1),
"col3":range(11, 15)})
print(data1) # Print first pandas DataFrame

data2 = pd.DataFrame({"col1":["x", "y"], # Create second pandas DataFrame
"col3":range(3, 1, - 1),
"col4":["new", "newest"]})
print(data2) # Print second pandas DataFrame

ignore_index = True,
sort = False)
print(data_concat) # Print combined DataFrame

Follow me on Social Media:

Рекомендации по теме
Комментарии
Автор

Nice, what if the column are not in order. I have 13 dataset i want to merge. In addition to column names been slightly different the column are not in same order

andrewbenyeogor
Автор

Hi great video! What if however you want to concat the data frames vertically but separate each one with a title?

Minhajul