How to Concatenate Column Values in Pandas DataFrame?
Many times we need to combine values in different columns into a single column. There can be many use cases of this, like combining first and last names of people in a list, combining day, month, and year into a single column of Date, etc. Now we’ll see how we can achieve this with the help of some examples.
Example 1: In this example, we’ll combine two columns of first name last name to a column name. To achieve this we’ll use the map function.
Example 2: Similarly, we can concatenate any number of columns in a dataframe. Let’s see through another example to concatenate three different columns of the day, month, and year in a single column Date.
We can take this process further and concatenate multiple columns from multiple different dataframes. In this example, we combine columns of dataframe df1 and df2 into a single dataframe.