Resampling करना
resample data की time frequency बदल देता है, जैसे daily numbers को weekly totals में बदलना।
In this page:
Syntax
df.resample("W").sum()
df.resample("M")["column"].mean()
Resampling
resample("W") datetime-indexed series को weekly bins में group करता है और इसे sum या mean जैसे aggregation की ज़रूरत होती है। Downsampling frequency घटाता है, जबकि upsampling उसे बढ़ाता है और gaps बनाता है जिन्हें ffill या interpolate से fill करना होता है।
आम rules में "D", "W" और "2D" शामिल हैं।
Note:
resample, time के लिए groupby है।
उदाहरण: Resampling
import pandas as pd
idx = pd.date_range("2024-01-01", periods=6, freq="D")
s = pd.Series([1, 2, 3, 4, 5, 6], index=idx)
print(s.resample("2D").sum())
print(s.resample("W").mean())
# Output:
# 2024-01-01 3
# 2024-01-03 7
# 2024-01-05 11
# Freq: 2D, dtype: int64
# 2024-01-07 3.5
# Freq: W-SUN, 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. #}
आम गलतियां
- aggregation भूल जाना
- DatetimeIndex के बिना resample करना
- upsampling करते समय gaps fill न करना
चैप्टर सारांश
- resample time frequency से regroup करता है
- इसे datetime index चाहिए
- Downsampling aggregate करता है
- Upsampling को filling चाहिए
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: