I have a series in datetime format, and need to change the day to 1 for each entry. I have thought of numerous simple solutions, but none of them w
datetime
1
You can use .apply and datetime.replace, eg:
.apply
datetime.replace
import pandas as pd from datetime import datetime ps = pd.Series([datetime(2014, 1, 7), datetime(2014, 3, 13), datetime(2014, 6, 12)]) new = ps.apply(lambda dt: dt.replace(day=1))
Gives:
0 2014-01-01 1 2014-03-01 2 2014-06-01 dtype: datetime64[ns]