I have a Yahoo finance daily stock price imported in a pandas dataframe. I want to use .resample()
to convert it to the monthly stock price by taking the price of the first QUOTED daily price of each month.
.resample('MS', how='first')
returns the correct price of each month but it changes the index to the first day of the month while in general the first day of a month for a quoted price maybe 2nd or 3rd of the month because of holidays and weekends.
How can I use resample()
by only resampling the existing dates and not changing them?
I think what you want is BMS (business month start):
Note: In earlier pandas this was done using the deprecated
how
kwarg:An alternative would be to groupby month and take the first with a plain ol' groupby (and e.g. use nth to get the first entry in each group):
Note: In earlier pandas this was done using the deprecated
TimeGrouper
: