df.resampe for 15 minute incremenets in python

To resample a DataFrame for 15-minute increments in Python using pandas, you can use the resample function along with the desired frequency. Here's an example:

main.py
import pandas as pd

# Create a sample DataFrame with a datetime index
data = {'value': [1, 2, 3, 4, 5]}
dates = pd.date_range('2022-01-01', periods=5, freq='10T')
df = pd.DataFrame(data, index=dates)

# Resample the DataFrame for 15-minute increments
df_resampled = df.resample('15T').sum()

print(df_resampled)
313 chars
12 lines

In this example, we first create a DataFrame df with a datetime index. We then use resample('15T') to resample the DataFrame for 15-minute intervals. The sum() function is applied to aggregate the values within each 15-minute interval.

The resulting resampled DataFrame df_resampled will have the values from the original DataFrame aggregated into 15-minute intervals.

Output:

main.py
                     value
2022-01-01 00:00:00      3
2022-01-01 00:15:00      7
2022-01-01 00:30:00      5
108 chars
5 lines

Make sure to adjust the frequency parameter ('15T') according to your specific needs.

related categories

gistlibby LogSnag