连接pandas datafram中的两列

2024-10-05 21:57:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我的pandas数据框中有year和month列,我想将它们串接成一个字符串,以便将它们转换为datetime。

df.info()给出

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

数据看起来像

years  month windSpeedM
1985    1   0.4

我在试这个

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

我有个错误

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

Tags: columns数据字符串pandasobjectyearnullnon