Skip to content

Instantly share code, notes, and snippets.

@hotohoto
Last active December 15, 2020 06:45
Show Gist options
  • Save hotohoto/79860b0a762bb37098407d59ac5f8e67 to your computer and use it in GitHub Desktop.
Save hotohoto/79860b0a762bb37098407d59ac5f8e67 to your computer and use it in GitHub Desktop.
Downsample a time-series dataset
import pandas as pd
import numpy as np
input_csv = "./weather_history_weekly.csv"
output_csv_2w = "./weather_history_2w.csv"
output_csv_monthly = "./weather_history_monthly.csv"
df = pd.read_csv(input_csv)
N = len(df)
all_columns = df.columns
df["Datetime"] = pd.to_datetime(df["Datetime"])
df.resample("2W", on="Datetime").mean().to_csv(output_csv_2w)
df.resample("1M", on="Datetime").mean().to_csv(output_csv_monthly)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment