How to Use rbind in Python? Last Updated : 28 Nov, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will discuss rbind() in python. Method 1: Use rbind() function with equal columns Here 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 dataframe1 is the first dataframedataframe2 is the second dataframe Example: Python3 # import pandas module import pandas as pd # create first dataframe data1 = pd.DataFrame({'fruits': ['apple', 'guava', 'mango', 'banana'], 'cost': [34, 56, 65, 45]}) # create second dataframe data2 = pd.DataFrame({'fruits': ['cuatard apple', 'guava', 'mango', 'papaya'], 'cost': [314, 86, 65, 51]}) # concat two columns pd.concat([data1, data2]) Output: Method 2: Use rbind() function with unequal columnsĀ Here 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, dataframe1 is the first dataframedataframe2 is the second dataframe Example: Python3 # import pandas module import pandas as pd # create first dataframe with 2 columns data1 = pd.DataFrame({'fruits': ['apple', 'guava', 'mango', 'banana'], 'cost': [34, 56, 65, 45]}) # create second dataframe with 3 columns data2 = pd.DataFrame({'fruits': ['cuatard apple', 'guava', 'mango', 'papaya'], 'cost': [314, 86, 65, 51], 'city': ['guntur', 'tenali', 'ponnur', 'hyd']}) # concat two columns pd.concat([data1, data2]) 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 # import pandas module import pandas as pd # create first dataframe with 2 columns data1 = pd.DataFrame({'fruits': ['apple', 'guava', 'mango', 'banana'], 'cost': [34, 56, 65, 45]}) # create second dataframe with 3 columns data2 = pd.DataFrame({'fruits': ['cuatard apple', 'guava', 'mango', 'papaya'], 'cost': [314, 86, 65, 51], 'city': ['guntur', 'tenali', 'ponnur', 'hyd']}) # concat two columns pd.concat([data1, data2]).reset_index(drop=True) Output: Comment More infoAdvertise with us Next Article How to Install python3-rtmidi in Windows? M manojkumarreddymallidi Follow Improve Article Tags : Pandas Python-pandas Pandas-DataFrame-Methods Similar Reads How to Install python3-rtmidi in Windows? RtMidi is a set of C++ classes that provide a cross-platform API for real-time MIDI input/output on Linux, macOS/OS X, and Windows. It is a Python binding package for RtMidi that uses Cython to wrap the RtMidi C++ interface. The API is essentially the same as in C++, but the naming scheme for classe 2 min read Red Black Tree in Python Red Black Tree is a self-balancing binary search tree where each node has an extra bit representing its color, either red or black. By constraining how nodes are colored during insertions and deletions, red-black trees ensure the tree remains approximately balanced during all operations, allowing fo 11 min read How to Use file.path() Function in R R programming language is becoming popular among developers, analysts, and mainly for data scientists. Students are eagerly learning R with Python language to use their analytical skills at their best. While learning any language, one is faced with many difficulties, and the individual learning R Pr 3 min read How to Install PyRTF with Python? RTF stands for "Rich Text Type" and is a Microsoft-developed file format. It's a way of encoding both text and pictures for usage in software. In the 7-bit ASCII text, RTF files contain control words, control symbols, and groups. This openly stated format is mostly used to exchange documents between 2 min read seek() function in Python In Python, the seek() function is used to move the file cursor to a specific position inside a file. This allows you to read or write at any part of the file instead of always starting from the beginning. For example, if you want to skip the first 10 characters while reading a file, you can do: Pyth 2 min read How to Address rbind Error in R When dealing with data in the R Programming Language, the rbind function is frequently used to merge entries from many data frames. However, you may face issues when using this function. Understanding the origins of these problems and how to fix them is critical for effective data processing in R. I 3 min read Like