0

I have a Data Frame Transformer contains various columns, Among are Name and Sampling_Point i want to filter and join them to form another column Sample_gas. i.e, Sample Table

Now i had filtered out df.NAME and df.SAMPLING_POINT but now want to join it and assigned it to some other column name called Sample_gas. I had written the code:

df['SAMPLE_GAS']=pd.concat([df.NAME,df.SAMPLING_POINT],axis=1)

but it give me error like:

Wrong number of items passed 2, placement implies 1

Please suggest the changes. The output should look like:

enter image description here

MD Rijwan
  • 471
  • 6
  • 15
  • 1
    Please provide a **[mcve]**. This means no images/links, just text. See also [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – jpp Sep 26 '18 at 18:21

2 Answers2

2
df['SAMPLE_GAS'] = df['NAME'].str.cat(df['SAMPLING_POINT'], sep=' ')

Or,

df['SAMPLE_GAS'] = [x + ' ' + y for x, y in zip(df['NAME'], df['SAMPLING_POINT'])]

For performance.

cs95
  • 379,657
  • 97
  • 704
  • 746
1

According to your output, you need to simply add your strings,

df['SAMPLE_GAS'] = df['NAME'] +' '+ df['SAMPLING_POINT']
Raunaq Jain
  • 917
  • 7
  • 13