Another solution using DataFrame.apply()
, with slightly less typing and more scalable when you want to join more columns:
cols = ['foo', 'bar', 'new']
df['combined'] = df[cols].apply(lambda row: '_'.join(row.values.astype(str)), axis=1)
More Related Contents:
- Why does the following code cant get value of n_fold = 1?
- How to change the order of DataFrame columns?
- Add missing dates to pandas dataframe
- Converting a Pandas GroupBy output from Series to DataFrame
- Pandas: sum DataFrame rows for given columns
- datetime dtypes in pandas read_csv
- Rename Pandas DataFrame Index
- Pandas DataFrame: replace all values in a column, based on condition
- What is the fastest way to upload a big csv file in notebook to work with python pandas?
- Calculate average of every x rows in a table and create new table
- How to check if any value is NaN in a Pandas DataFrame
- Convert row to column header for Pandas DataFrame,
- Removing prefix from column names in Pandas
- Select multiple ranges of columns in Pandas DataFrame
- Python Pandas update a dataframe value from another dataframe
- Mapping columns from one dataframe to another to create a new column [duplicate]
- How can I replicate rows in Pandas?
- Action with pandas SettingWithCopyWarning
- python dataframe pandas drop column using int
- How to create a DataFrame of random integers with Pandas?
- How to plot two columns of a pandas data frame using points
- How to read a list of parquet files from S3 as a pandas dataframe using pyarrow?
- Create new column based on values from other columns / apply a function of multiple columns, row-wise in Pandas
- Python Pandas – Merge based on substring in string
- append dictionary to data frame
- Pandas groupby and aggregation output should include all the original columns (including the ones not aggregated on)
- Selecting a range of columns in a dataframe
- Replace NaN with empty list in a pandas dataframe
- Get weekday/day-of-week for Datetime column of DataFrame
- When is it appropriate to use df.value_counts() vs df.groupby(‘…’).count()?