Concatenate Pandas dataframes (like a union function in SQL)


import pandas as pd
#create a dataframe
raw_data = {'name': ['Willard Morris', 'Al Jennings'],
        'age': [20, 19],
        'favorite_color': ['blue', 'red'],
        'grade': [88, 92]}
df = pd.DataFrame(raw_data, index = ['Willard Morris', 'Al Jennings'])
df
age favorite_color grade name
Willard Morris 20 blue 88 Willard Morris
Al Jennings 19 red 92 Al Jennings

#create another dataframe
raw_data_2 = {'name': [ 'Omar Mullins', 'Spencer McDaniel'],
        'age': [22, 21],
        'favorite_color': ['yellow', "green"],
        'grade': [95, 70]}
df_2 = pd.DataFrame(raw_data, index = ['Omar Mullins', 'Spencer McDaniel'])
df_2
age favorite_color grade name
Omar Mullins 20 blue 88 Willard Morris
Spencer McDaniel 19 red 92 Al Jennings

#create list of dataframes we want to concatenate
dataframes = [df, df_2]
#concatenate the dataframes. analagous to union function in sql
dataframes_concat = pd.concat(dataframes)
dataframes_concat
age favorite_color grade name
Willard Morris 20 blue 88 Willard Morris
Al Jennings 19 red 92 Al Jennings
Omar Mullins 20 blue 88 Willard Morris
Spencer McDaniel 19 red 92 Al Jennings