August 2019
Beginner
482 pages
12h 56m
English
On occasion, we need to join multiple dataframes together. There could be different ways to do that—let's take a look.
First and foremost, if you have multiple dataframes with the same columns, and you want to join them—never do that iteratively—try to do that once, by passing a list of all of them to the pd.concat function with the axis=0 and sort=False arguments (unless you need to sort them):
>>> df.shape(3, 4)>>> double = pd.concat([df, df], axis=0, sort=False)>>> double.shape(6, 4)
Similarly, pd.concat can merge multiple dataframes horizontally if axis=1:
>>> pd.concat([df, df], axis=1) x y z new_column x y z new_column0 1 a False -1 1 a False -11 2 b True -1 2 b True -12 3 c False -1 3 c False -1
In this example, we group two ...