python - Pandas date_range to generate monthly data at beginning of the month -
i'm trying generate date range of monthly data day @ beginning of month:
pd.date_range(start='1/1/1980', end='11/1/1991', freq='m')
this generates 1/31/1980
, 2/29/1980
, , on. instead, want 1/1/1980
, 2/1/1980
,...
i've seen other question ask generating data on specific day of month, answers saying wasn't possible, beginning of month surely must possible!
you can changing freq
argument 'm'
'ms'
:
d = pandas.date_range(start='1/1/1980', end='11/1/1990', freq='ms') print(d)
this should print:
datetimeindex(['1980-01-01', '1980-02-01', '1980-03-01', '1980-04-01', '1980-05-01', '1980-06-01', '1980-07-01', '1980-08-01', '1980-09-01', '1980-10-01', ... '1990-02-01', '1990-03-01', '1990-04-01', '1990-05-01', '1990-06-01', '1990-07-01', '1990-08-01', '1990-09-01', '1990-10-01', '1990-11-01'], dtype='datetime64[ns]', length=131, freq='ms', tz=none)
look offset aliases part of documentation. there states 'm'
end of month (month end frequency) while 'ms'
beginning (month start frequency).
Comments
Post a Comment