i have a dataframe that contains forecasts for 7 days ahead, and i wnat to take always the first day of the forecast and concat it such that i will get a time series of the first days of the forecast in python

Assuming that you have a Pandas DataFrame named df with the index representing the dates for the 7 days ahead and the values representing the forecasts, you can use the resample method to take only the values that correspond to the first day of the forecast and create a new time series with these values. Here is an example of how to do it:

main.py
import pandas as pd

# Create example DataFrame with forecasts for 7 days ahead
dates = pd.date_range(start="2022-01-01", periods=7, freq="D")
values = [1, 2, 3, 4, 5, 6, 7]
df = pd.DataFrame(values, columns=["forecasts"], index=dates)

# Resample DataFrame to only include values for the first day of the forecast
ts = df.resample("D").first()
345 chars
10 lines

In this example, ts will be a new time series with the values [1, NaN, NaN, NaN, NaN, NaN, NaN], where the first value corresponds to the first day of the forecast and the other values are NaN because there are no forecasts for those dates.

related categories

gistlibby LogSnag