Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] converting Pandas DataFrame into TimeSeries object #1522

Closed
Nikodemski2002 opened this issue Jan 29, 2023 · 4 comments · Fixed by #1938
Closed

[BUG] converting Pandas DataFrame into TimeSeries object #1522

Nikodemski2002 opened this issue Jan 29, 2023 · 4 comments · Fixed by #1938
Labels
bug Something isn't working

Comments

@Nikodemski2002
Copy link

Describe the bug
Hi, I have a problem with converting Pandas DataFrame into Darts TimeSeries object namely, my Pandas DataFrame consists of the datetime64 index and 4 columns of float64 data I want to have in the TimeSeries object. After executing below code, I get an error: coordinate component has dimensions ('_field',), but these are not a subset of the DataArray dimensions ('_time', 'component', 'sample')

To Reproduce
TSDF = TimeSeries.from_dataframe(modeldf)

Expected behavior
Getting a Darts TimeSeries object.

System (please complete the following information):

  • Python version: 3.9
  • darts version 0.23.1

Additional context
image

Kind regards
Nikodem

@Nikodemski2002 Nikodemski2002 added bug Something isn't working triage Issue waiting for triaging labels Jan 29, 2023
@alexcolpitts96
Copy link
Contributor

It is hard to infer what is going on from the provided info; however, here is a minimal example that should work:

import darts
import pandas as pd
import numpy as np

df = pd.DataFrame(
            data=np.random.randint(0, 100, size=(100, 4)), columns=list("ABCD"),
            index=pd.date_range(start=0, periods=100, freq='1D'),
        )

ts = darts.TimeSeries.from_dataframe(df)

If that works and your code is still not working, you should provide more information about your code. I also will recommend reinstalling darts or creating a new venv, conda env, etc. To avoid having to create a new environment, you can force reinstall darts using

pip install darts --ignore-installed

@hrzn
Copy link
Contributor

hrzn commented Jan 31, 2023

+1, the code TSDF = TimeSeries.from_dataframe(modeldf) is not reproducible. Please provide a fully self-contained code snippet.

@mhadi4194
Copy link

mhadi4194 commented Mar 28, 2023

I ran into same issue.
looks like issue is because of column name index.
here is code to reproduce:

df2 = pd.DataFrame(
            data=np.random.randint(0, 100, size=(100, 1))
            ,index=pd.date_range(start=0, periods=100, freq='1D'),columns=['y']
        ).reset_index()
df2 = df2[df2['index'].dt.day != 2] # data has incomplete date
df2['id'] = list("ABCD") * 25 # multiple time series
df2 = df2.pivot(columns='id',values='y',index='index').fillna(value=0).reset_index()

series = TimeSeries.from_dataframe(df2
                                   ,time_col='index'
                                   ,fill_missing_dates=True
                                   ,freq='1D'
                                   
                                   ,fillna_value=0
                                  )

Error message:

ValueError: coordinate component has dimensions ('id',), but these are not a subset of the DataArray dimensions ('index', 'component', 'sample')

solutions:
remove column index name:

df2.columns.name = None

@madtoinou
Copy link
Collaborator

Thank you @mhadi4194 for pinpointing the source of the error and suggesting a solution, I opened a PR with a fix.

@madtoinou madtoinou removed the triage Issue waiting for triaging label Aug 7, 2023
@github-project-automation github-project-automation bot moved this to Released in darts Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Released
Development

Successfully merging a pull request may close this issue.

5 participants