So this recipe is a short example on how to concatenate 2 or more dataframes. Let's get started.
import pandas as pd import seaborn as sb
Let's pause and look at these imports. Pandas is generally used for performing mathematical operation and preferably over arrays. Seaborn is just for importing dataset for now.
df = sb.load_dataset('tips') df.to_csv('tips.csv') df_a=df.iloc[:,0:2] df_b=df.iloc[:,2:4] df_c=df.iloc[:,4:]
Here we have simply imported tips dataset from seaborn library. Now we have broken down the dataset into 3 dataframes: df_a, df_b and df_c.
df_merged = pd.concat([df_a, df_b,df_c], axis=1)
Here, we are merging 3 dataframes on columns. We can do various other operation while concating.
print(df) print(df_a) print(df_b) print(df_c) print(df_merged)
Simply use print function to print all the dataframes created
Once we run the above code snippet, we will see:
Scroll down the ipython file to visualize the final output.