|
In this article, we will discuss rbind() in python. Method 1: Use rbind() function with equal columnsHere we have to take 2 dataframes with equal columns and apply concat() function. This will combine the rows based on columns. Syntax: pandas.concat([dataframe1, dataframe2]) where
Example: Python3
Output: Method 2: Use rbind() function with unequal columnsHere the two dataframes columns are not equal, In this scenario, the unmatched column will get NAN replaced rows in its column. Syntax: pandas.concat([dataframe1, dataframe2]) where,
Example: Python3
Output: Here we observed that the index of the rows again starts from 0, in order to avoid this, we have to use the .reset_index() method. This will reset the index of the new dataframe. Syntax: pandas.concat([dataframe1, dataframe2]).reset_index(drop=True) Example: Python3
Output: |
Reffered: https://www.geeksforgeeks.org
Pandas |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |