-1

I have data stored in an excel sheet. It has 50 columns and 100 rows. I have read the data into jupyter lab. I want to concatenate two columns which consists of text values i.e, string. I have tried concatenating them using "pd.concat(['column1','column2'])". But, there was an error that stated "TypeError: cannot concatenate object of type ''; only Series and DataFrame objs are valid".

For example, Consider the following columns present in a data set, Input:

   column 1
   a
   b
   c

   column 2
   d
   e
   f

This is the format in which I want the output. Output:

 New column
 ad
 be
 cf

Could you please let me know how to do this?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • Question is about `pandas`, and not `machine-learning` - kindly use the correct tags and do not spam irrelevant ones (edited). – desertnaut May 17 '20 at 12:29

1 Answers1

0

Try this:

import pandas as pd

#create dataframe
df = pd.DataFrame()
df['col1'] = ['a','b','c']
df['col2'] = ['d','e','f']

#new column
df['new_col'] = df['col1'] + df['col2']
Joke
  • 30
  • 2