How to create a time series with darts having weekly frequency?
When having weekly data as follows:
import pandas as pd
df = pd.DataFrame({
'Date' : [
pd.to_datetime('2022-12-05'),
pd.to_datetime('2022-12-12'),
pd.to_datetime('2022-12-19'),
pd.to_datetime('2022-12-26')],
'Variable': [10,21,23,24]})
I am struggling to get the correct freq
as weekly:
from darts import TimeSeries
# I use freq = day in order to not to get an error.
TimeSeries.from_dataframe(df, 'Date', "Variable", freq="d")
I'm not sure about your issue. Your data are already on a weekly basis. It seems there is a typo with that date here:
pd.to_datetime('2022-12-02')
, which should probably bepd.to_datetime('2022-12-02')
.I don't know if that was the purpose, but personally, I would handle the data (missing data, frequency, etc.) with either numpy or pandas before creating a TimeSeries object with darts. Numpy and/or pandas are larger libraries that have functionalities to do that. It's also a good practice to check the quality of your data upfront.
Going back to your question, that should do the trick :
I assume you meant
2022-12-12
and not2022-12-02