i have some data like this
df = pd.DataFrame(index = pd.date_range('01/27/2018',periods = 290,freq = 'H'))
df['v'] = 1
In [85]: df
Out[85]:
v
2018-01-27 00:00:00 1
2018-01-27 01:00:00 1
2018-01-27 02:00:00 1
2018-01-27 03:00:00 1
2018-01-27 04:00:00 1
2018-01-27 05:00:00 1
2018-01-27 06:00:00 1
2018-01-27 07:00:00 1
2018-01-27 08:00:00 1
2018-01-27 09:00:00 1
2018-01-27 10:00:00 1
2018-01-27 11:00:00 1
2018-01-27 12:00:00 1
... ..
2018-02-07 12:00:00 1
2018-02-07 13:00:00 1
2018-02-07 14:00:00 1
2018-02-07 15:00:00 1
2018-02-07 16:00:00 1
2018-02-07 17:00:00 1
2018-02-07 18:00:00 1
2018-02-07 19:00:00 1
2018-02-07 20:00:00 1
2018-02-07 21:00:00 1
2018-02-07 22:00:00 1
2018-02-07 23:00:00 1
2018-02-08 00:00:00 1
2018-02-08 01:00:00 1
[290 rows x 1 columns]
and i resample by month, the index show Last day of last month, i want the index show the 1st of the month
In [87]: df.resample('M', how='sum')
Out[87]:
v
2018-01-31 120
2018-02-28 170
The effect I want is like this, so how can i write my code
Out[87]:
v
2018-01-01 120
2018-02-01 170
As @sacul mentioned in comment, go with MS
.
Available options:
B business day frequency
C custom business day frequency (experimental)
D calendar day frequency
W weekly frequency
M month end frequency
SM semi-month end frequency (15th and end of month)
BM business month end frequency
CBM custom business month end frequency
MS month start frequency
SMS semi-month start frequency (1st and 15th)
BMS business month start frequency
CBMS custom business month start frequency
Q quarter end frequency
BQ business quarter endfrequency
QS quarter start frequency
BQS business quarter start frequency
A year end frequency
BA business year end frequency
AS year start frequency
BAS business year start frequency
BH business hour frequency
H hourly frequency
T minutely frequency
S secondly frequency
L milliseonds
U microseconds
N nanoseconds
Reference: Offset Aliases
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With