Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Resampling and Frequency Conversion | Section
Mastering Time Series Fundamentals
Sectie 1. Hoofdstuk 6
single

single

bookResampling and Frequency Conversion

Veeg om het menu te tonen

123456789
import pandas as pd # Create a simple daily time series dates = pd.date_range("2024-01-01", periods=90, freq="D") values = pd.Series(range(90), index=dates) # Resample to monthly frequency, taking the average for each month monthly_avg = values.resample("ME").mean() print(monthly_avg)
copy

When working with time series data in pandas, the resample method allows you to convert your data from one frequency to another, such as from daily to monthly or weekly. This is useful for summarizing, aggregating, or aligning your data to a different time scale.

The resample method works similarly to groupby, but it is specifically designed for time series data with a DatetimeIndex. You specify a new frequency using a frequency string, such as "ME" for month-end, "W" for week-end, or "D" for daily. After resampling, you apply an aggregation function, such as .mean(), .sum(), .max(), or .min(), to summarize the values within each new period.

In the code sample above, the daily series is resampled to monthly frequency using "ME", and the .mean() function calculates the average value for each month. You can use other frequency strings to resample to different periods, and choose the aggregation function that best fits your analysis needs.

Taak

Swipe to start coding

Resample a daily time series to weekly frequency and compute the sum for each week.

  • Use the resample method on the input series with a frequency of "W".
  • Aggregate the values within each week using the sum function.
  • Return the resulting weekly series.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 6
single

single

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

some-alt