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.
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
data2 = pd.concat([data, new_rows], # List of data Frames to concatenate
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
pd.concat([data2, new_cols], # List of data Frames to concatenate
axis=1) # Axis = 1 to concat by column
Subscribe : https://www.youtube.com/c/DataDaft?sub_confirmation=1
#python