neuniversity / ALY6140

1 stars 3 forks source link

How to combine two columns (data cleaning)? #38

Open xiranzhao opened 5 years ago

xiranzhao commented 5 years ago
screen shot 2018-12-08 at 11 05 43 pm

Hi, I am trying to add ALT_NAME column to SITE_NAME column, I found code from internet,df['SITE_NAME'] = df['SITE_NAME'].map(str) + df['ALT_NAME'] df.head(). But it still doesn't work. please help!

heena007 commented 5 years ago

I tried your code on my dataframe and its working. I think it might have to do something with the datatype of your columns , you are trying to concatenate.

xyz04 commented 5 years ago

Hi Xiran,

According to your question, I found a code that maybe can help you. By default, axis=0 is vertical splicing, concat([df1,df2]) or df1.append(df2). The horizontal splicing at axis=1, where there is concat([df1,df2],axis=1) or merge(df1,df2,left_index=True,right_index=True,how='outer'). I hope that will help you.

Thanks, Xinyu Zhang

echolq012 commented 5 years ago

Hi Xiran, In my project, I have merged two columns. If you have the same listing ID column, you can merge those two columns. Please try to use pd.merge() in your dataset. Hope it helps you.

Best, Qing Li

ThatkidfromA commented 5 years ago

Hi Xiran,

This article has good documentation about pandas merger: "https://pandas.pydata.org/pandas-docs/stable/merging.html"