简体   繁体   中英

Resampling daily to monthly data with Pandas

I am trying to change daily to monthly data. Lets say I have close of daily data of AAPL in “C”:

2015-10-23    119.0800
2015-10-26    115.2800
2015-10-27    114.5500
2015-10-28    119.2700
2015-10-29    120.5300
2015-10-30    119.5000
2015-11-02    121.1800
2015-11-03    122.5700
2015-11-04    122.0000
2015-11-05    120.9200
2015-11-06    121.0600
2015-11-09    120.5700
2015-11-10    116.7700
2015-11-11    116.1100
2015-11-12    115.7200
2015-11-13    112.3400
2015-11-16    114.1750
2015-11-17    113.6900
2015-11-18    117.2900
2015-11-19    118.7800
2015-11-20    119.3000
2015-11-23    117.7500
2015-11-24    118.8800
2015-11-25    118.0300
2015-11-27    117.8100
2015-11-30    118.3000
2015-12-01    117.3400
2015-12-02    116.2800
2015-12-03    115.2000
2015-12-04    119.0300

I am trying to resample to Monthly with:

C=C.resample('M')

I get monthly frequency, but the numbers do not match:

2015-08-31    119.7200
2015-09-30    116.4100
2015-10-31    120.5300
2015-11-30    122.5700
2015-12-31    119.0300
Freq: M, Name: close, dtype: float64

Close of 2015-11-30 should be 118.30 (as last daily close in November), but I am getting 122.57.

What am I missing here? Thank you.

Thank you.

This works: C2=C.groupby([lambda x: x.year,lambda x: x.month]).last()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM