How to Concatenate Data Frames in Pandas (Python)

preview_player
Показать описание
↓ Code Available Below! ↓

This video shows how to concatenate data frames using the pandas library in Python. Data frame concatenation, also known as pasting or binding, just means joining together two data frames that have either the same columns or the same rows. In other words, using concatenate lets you add more rows or columns to an existing data frame. Concatenation should not be confused with join (merge) operations that involve combining the records of two data tables based on one or more shared key columns.

If you find this video useful, like, share and subscribe to support the channel!

Code used in this Python Code Clip:

import pandas as pd

data = pd.DataFrame({"character": ["Goku","Vegeta", "Nappa","Gohan","Piccolo"],
"power level": [12000, 16000, 4000, 1500, 3000]})

data

new_rows = pd.DataFrame({"character": ["Tien","Yamcha", "Krillin"],
"power level": [2000, 1600, 2000]})

new_rows

# Concatenate Data Frames by Rows

axis=0, # Axis = 0 to concat by row
ignore_index=True)

data2

new_cols = pd.DataFrame({"uniform color": ["orange", "blue", "black", "orange",
"purple", "green", "orange", "orange"],
"species":["saiyan","saiyan","saiyan","half saiyan",
"namak","human","human","human"]})

new_cols

# Concatenate Data Frames by Columns

axis=1) # Axis = 1 to concat by column

* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large < and > symbols in place of the standard sized ones. .

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

THANK YOU SO MUCH FOR THE DETAILED EXPLANATION!!! FINALLY, I GET TO RUN THE CODE WITHOUT ERRORS!!!

nashaluhan
Автор

I really really really like your so useful, simple, explicit and extremely organized

clarama
Автор

Sir .. my requirement is two dataframe but not pandas just simply temporary table create dataframe based on this df=(source lat, source long) and df2 =( dest lat, dest long) now i want to concat these df and make a new dataframe df3=( source lat, source long, dest lat, dest long) is it possible

insane
Автор

If we have only 1 extra column in df1 and that is concated with df2 the extra values(the values except df1) in concated df will be NaN so how can we distinguish between NaN values from orginal data frame and this newly created NaN values ?

pavanraj