Net-informations.com

Combine multiple column values into a single column

Lets create a DataFrame with two columns First_Name and Last_Name.

If both columns (First_Name and Last_Name ) are strings, you can concatenate them directly to a new column.

Join the columns First_Name and Last_Name to a new column FullName

Join Different columns type in Pandas

If one (or both) of the columns are not same typed, you should convert it (them) first and then concatenate them directly to a new column.

Here Name and Age are different data types, then you have to convert the column types as same and then concatenate it.

Using agg() to join pandas column

If you need to join multiple string columns , you can use agg().

Using agg()

Using apply()

You can use DataFrame.apply() for concatenate multiple column values into a single column, with slightly less typing and more scalable when you want to join multiple columns .










net-informations.com (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About