合并数据时,我一直遇到错误:
record_id month day year sex
1 7 17 1977 M
2 7 15 1979 M
3 7 26 1978 F
4 7 16 1973 M
Run Code Online (Sandbox Code Playgroud)
我尝试了将月份、日期和年份合并为一列的不同方法:
1. surveys_df['date'] = surveys_df['month'].astype(str) + surveys_df['day'] + surveys_df['year']
2. surveys_df['Date'] = pd.to_datetime(surveys_df[['month', 'day', 'year']])
3. r= pd.to_datetime(surveys_df[['year', 'month', 'day']])
4. surveys_df['date'] = pd.to_datetime(surveys_df[['day','month','year']])
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
ValueError:无法组合日期时间:日期超出范围
我知道我可以通过使用error= 'coerce'来强制它,但我想避免使用该方法。