Let’s see the different methods to join two text columns into a single column.
Method #1: Using cat() function
We can also use different separators during join. e.g. -, _, ” ” etc.
Method #2: Using lambda function
This method generalizes to an arbitrary number of string columns by replacing df[[‘First’, ‘Last’]] with any column slice of your dataframe, e.g. df.iloc[:, 0:2].apply(lambda x: ‘ ‘.join(x), axis=1).
Method #3: Using + operator
We need to convert data frame elements into string before join. We can also use different separators during join, e.g. -, _, ‘ ‘ etc.
- Split a text column into two columns in Pandas DataFrame
- Create a new column in Pandas DataFrame based on the existing columns
- How to fixed one column and scrollable other column or columns in Bootstrap ?
- Python | Pandas str.join() to join string/list elements with passed delimiter
- Python | Pandas DataFrame.columns
- Collapse multiple Columns in Pandas
- Difference of two columns in Pandas dataframe
- How to rename columns in Pandas DataFrame
- Python program to Reverse a single line of a text file
- Dealing with Rows and Columns in Pandas DataFrame
- Iterating over rows and columns in Pandas DataFrame
- How to drop one or multiple columns in Pandas Dataframe
- Conditional operation on Pandas DataFrame columns
- Getting frequency counts of a columns in Pandas DataFrame
- How to select multiple columns in a pandas dataframe
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.