Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

merging 3 columns to single column using python pandas

merging 3 columns to single column using python pandas

New Contributor

Hi ,

I have csv file which is having columns i.e

i want to combine(merge) zipcode, housenumber, street to one column saying address

I can read those file after that i tried the below code its getting error

import pandas as pd
import csv
input= pd.readcsv("/root/demo_stats_extraction/fsm_src/logs/multithread/src/cmts_cm_mapping.csv")
df['Address'] = df[df.columns[3:5]].apply(lambda x: ','.join(x.astype(int).astype(str)),axis=1)

please help !!

1 REPLY 1
Highlighted

Re: merging 3 columns to single column using python pandas

Contributor

@hema moger,

You can simply do that

df['Address'] = df[df.columns[3:5]].apply(lambda x: ','.join(x.map(str)),axis=1)