jarry jafery
jarry jafery

Reputation: 1036

concatenate two columns in pandas dataframe

I have year and month column in my pandas data frame and i want to concatenate them by as a string so that i can convert them into datetime.

df.info() gives

Data columns (total 3 columns):
years         372 non-null object
months        372 non-null object
windSpeedM    371 non-null float64

and the data looks like

years  month windSpeedM
1985    1   0.4

i am trying this

ff2['date'] = ff2['years']+'-'+ff2['months']+'-'+'01'

i am getting an error

TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('S21') dtype('S21') dtype('S21')

Upvotes: 1

Views: 11506

Answers (1)

Amey Kumar Samala
Amey Kumar Samala

Reputation: 944

ff2['date'] = ff2['years'].map(str)+'-'+ff2['months'].map(str)+'-'+'01'

Upvotes: 3

Related Questions