Concatenate (join) two or more datasets vertically (along rows) or horizontally (along columns). This is useful when you have multiple datasets with the same structure that you want to combine into a single dataset.

Axis

The concat function is a method utilized to merge multiple datasets, typically in the form of tables or data structures with rows and columns, along a specific axis. This process combines the data structures by appending them in the chosen direction. There are two primary axes for concatenation:

  • Row-wise concatenation (axis=0): In this approach, the datasets are merged along the row axis. The resulting table consists of the rows of the second dataset appended below the rows of the first dataset. For successful row-wise concatenation, the datasets must have identical column structures, including the same number of columns and matching column names or appropriately managed column names.
  • Column-wise concatenation (axis=1): In this approach, the datasets are merged along the column axis. The resulting table consists of the columns of the second dataset appended to the right of the columns of the first dataset. For successful column-wise concatenation, the datasets must have identical row structures, including the same number of rows and matching row indices or appropriately managed row indices.

The concat function enables users to merge datasets in a structured manner, either vertically (row-wise) or horizontally (column-wise), depending on the desired output and data organization.

How

  • Inner join: An inner join combines datasets by matching rows based on a common attribute (e.g., a shared column). The resulting dataset includes only those rows that have matching values in the common attribute from both datasets. Rows that do not have matching values in the shared attribute are excluded from the result.
  • Outer join: An outer join combines datasets by including all rows from both datasets, regardless of whether there is a match in the common attribute. There are three types of outer joins: left outer join, right outer join, and full outer join. In the case of missing matches, the missing values are filled with a placeholder, such as 'NaN' or 'null'.

These options allow you to customize the concatenation process based on your requirements and the structure of your datasets.

Example:

Dataset A:

AB
12
34

Dataset B:

AB
56
78

Concatenate vertically (along rows):

AB
12
34
56
78