Combining Year, Month, Day Columns Into A Single Date Column With Pandas
I keep running into an error when combining my data: record_id month day year sex 1 7 17 1977 M 2 7 15 1979 M 3 7 26
Solution 1:
pd.to_datetime(df[['year', 'month', 'day']])
0 1977-07-17
1 1979-07-15
2 1978-07-26
3 1973-07-16
dtype: datetime64[ns]
If there are invalid combinations you want to NaTify, then add the errors='coerce'
argument.
Post a Comment for "Combining Year, Month, Day Columns Into A Single Date Column With Pandas"