← Back to Pandas Course | Chapter 10: Time Series | Lesson 3 of 7

Resampling करना

resample data की time frequency बदल देता है, जैसे daily numbers को weekly totals में बदलना।

In this page:

  1. Resampling
Syntax
python
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

python
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. #}
आम गलतियां
  1. aggregation भूल जाना
  2. DatetimeIndex के बिना resample करना
  3. 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:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.