Home > Back-end >  Add the first day of each month to year month date in python
Add the first day of each month to year month date in python

Time:12-16

I have a dataframe that contains 3 columns year month and SPEI value I want to add day column that contains the first day of each month
this is an example

CodePudding user response:

If need new column with first day use:

df['day'] = 1

If need datetime with first day:

df['datetime'] = pd.to_datetime(df[['year','month']].assign(day=1))
  • Related