1
votes

I am trying to save some data in csv file using a function called "save_dataset" from a library named "orkg" and based on Python.

In the dataset, I have to save some Date values, the python compiler doesn't accept the separtor which is a point (.) between the month and year and shows me a syntax error: SyntaxError: invalid syntax This is the code I used:

datasetID = orkg.resources.save_dataset(file="data.csv", label=["cc_variant", "Date","NEE"], dimensions=[
        (Fallow, 18.10.2016, 5231861), (Fallow, 19.10.2016, 3675274), (Fallow, 24.10.2016, 3459082), (Mix4, 18.10.2016, -51686837), 
        (Mix12, 18.10.2016, -61711000), (Mustard, 18.10.2016, -18224568), (Mix4, 19.10.2016, -10263776), 
        (Mix12, 19.10.2016, -43155887), (Mustard, 19.10.2016, -13904121), (Mustard, 24.10.2016, -11409939),
        (Mix12, 24.10.2016, -40021260), (Mix4, 24.10.2016, -17533208)]
])

I am not sure if the import of panda library is necessary or shall I change the format of date ?

1
What type do you expect 18.10.2016 to be? A float? A string? A tuple? A datetime.date, or datetime.datetime? - MisterMiyagi
@MisterMiyagi thanks for trying to help me. I am copied the data direct from a csv file, the 18.10.2016 is a date so I think the best option here is a datetime.date - Anouar

1 Answers

1
votes

Basically your input like 19.10.2016 will not be understood by python. You can test this by opening a python interactive shell and simply typing 19.10.2016 and you will get the same error.

What you probably want is to pass this as a string "19.10.2016" to your save_dataset call, so that the package can take a look at the string, figure out that it's a date and do whatever is appropriate.

The other option that you have (and which will work nicely with most other packages) is to use datetime objects:

>>> from datetime import date
>>> date.fromisoformat('2019-12-04')
datetime.date(2019, 12, 4)

So tl;dr: Wrap all the dates in quotation marks or use the datetime package ;)