[英]what does first() do in pandas resample?
as the title implies:正如标题所暗示的:
IN[1] :
dates = pd.date_range('10/10/2018', periods=11, freq='D')
close_prices = np.arange(len(dates))
close = pd.Series(close_prices, dates)
close
OUT[1]:
2018-10-10 0
2018-10-11 1
2018-10-12 2
2018-10-13 3
2018-10-14 4
2018-10-15 5
2018-10-16 6
2018-10-17 7
2018-10-18 8
2018-10-19 9
2018-10-20 10
IN[2] : close.resample('W').first()
OUT[2] :
2018-10-14 0
2018-10-21 5
Freq: W-SUN, dtype: int64
first what does resample & first do?首先 resample & first 做什么?
and why do we have this date 2018-10-21 as it was not existing in the series and based on what we have the 0 and 5?为什么我们有这个日期2018-10-21 ,因为它在系列中不存在并且基于我们拥有的 0 和 5?
Thanks谢谢
resample('W')
reorders and groups the dates so that they're each a full week. resample('W')
对日期进行重新排序和分组,以使它们各自为一整周。
first()
selects each week. first()
每周选择一次。
You have resampled your data by week.您已按周重新采样数据。 '2018-10-14' and '2018-10-21' are the last dates of each resampled week (each a Sunday).
“2018-10-14”和“2018-10-21”是每个重新采样周的最后日期(每个星期天)。 So by resampling, you have aggregated your data into weekly samples displayed on the Sundays on 10-14 and 10-21.
因此,通过重新采样,您已将数据聚合为在 10-14 和 10-21 的星期日显示的每周样本。 0 and 5 each refer to the count at the beginning of each respective week (in other words, the counts on 10-10 and 10-15, which would be the beginning Mondays of the resampled weeks ending on Sundays.
0 和 5 分别指的是每个相应周开始时的计数(换句话说,10-10 和 10-15 的计数,这将是重新采样周的开始星期一,以星期日结束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.