Rolling Windows का उपयोग
Rolling windows हाल की values के एक sliding group पर एक statistic calculate करते हैं, जैसे moving average।
In this page:
Syntax
s.rolling(window=n).mean()
df["column"].rolling(window=n).sum()
Rolling windows
s.rolling(window=3).mean() हर value को उससे पहले की दो values के साथ average करता है। min_periods सेट न करने पर पहले window-1 results NaN होते हैं। Rolling sum, std, min और max को भी support करता है, और "3D" जैसी time-based windows को भी।
Note:
min_periods=1 शुरुआती NaN values से बचाता है।
उदाहरण: Rolling windows
import pandas as pd
s = pd.Series([10, 20, 30, 40, 50])
print(s.rolling(3).mean())
print(s.rolling(3, min_periods=1).sum())
print(s.expanding().mean())
# Output:
# 0 NaN
# 1 NaN
# 2 20.0
# 3 30.0
# 4 40.0
# dtype: float64
# 0 10.0
# 1 30.0
# 2 60.0
# 3 90.0
# 4 120.0
# dtype: float64
# 0 10.0
# 1 15.0
# 2 20.0
# 3 25.0
# 4 30.0
# dtype: float64
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- यह भूल जाना कि पहली values NaN होती हैं
- rolling को expanding के साथ confuse करना
- छोटे data के लिए बहुत बड़ी window का उपयोग करना
चैप्टर सारांश
- rolling data पर एक window slide करता है
- Default रूप से पहले results NaN होते हैं
- min_periods इसे ढीला करता है
- mean, sum, std और अधिक के साथ काम करता है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: