[英]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”:
可以说我在“ C”中有AAPL的每日数据:
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. 2015-11-30的收盘价应该为118.30(作为11月的最后一天收盘价),但我的收盘价为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() 这有效:C2 = C.groupby([lambda x:x.year,lambda x:x.month])。last()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.