0

I have a very easy question: I try to read following data into an Dataframe https://www.ecdc.europa.eu/en/publications-data/download-data-response-measures-covid-19

If I use folllowing code, the output is not in the format I expect it to be as the CSV is not "seperated":

dmeasures = pd.read_csv('file.csv',sep=",",header=0,)
print (dmeasures)

Any ideas where my mistake is with the seperator?

1
  • 1
    It works for me, you just forgot quotation marks around the file. dmeasures = pd.read_csv("file.csv", sep=",", header=0,) Commented Nov 4, 2020 at 10:36

2 Answers 2

2

You can read CSV directly from URL:

url = 'https://www.ecdc.europa.eu/sites/default/files/documents/Data_response_graphs_2020-10-21.csv'
dmeasures = pd.read_csv(url, sep=",")
print(dmeasures)

Prints:

            Country            Response_measure  date_start    date_end
0           Austria                 ClosDaycare  2020-03-16  2020-05-04
1           Austria                    ClosHigh  2020-03-16  2020-09-30
2           Austria                    ClosPrim  2020-03-16  2020-05-18
3           Austria                  ClosPubAny  2020-03-16  2020-04-13
4           Austria           ClosPubAnyPartial  2020-04-14         NaN
..              ...                         ...         ...         ...
460  United Kingdom        StayHomeOrderPartial  2020-05-10  2020-07-04
461  United Kingdom               StayHomeRiskG  2020-03-16  2020-07-05
462  United Kingdom        StayHomeRiskGPartial  2020-07-06  2020-08-01
463  United Kingdom         TeleworkingClosures  2020-03-16  2020-05-09
464  United Kingdom  TeleworkingClosuresPartial  2020-05-10         NaN

[465 rows x 4 columns]
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for your help- I know that I can read in the URL, but I need to save the dataset on an server to ensure data consistency. If I read in the URL, everything works fine. However, if I save the file, the separation does not work...any ideas? I think it is not directly a python issue...
@Sebastian You can save the dataframe to file as dmeasures.to_csv('file.csv', index=False)
@ Andrej, sorry for the missunderstanding: I already have this dataset on a server, but an older version which I need to use- when reading in this older version, I have the issue. I tried the same with the "current" dataset and face the same problem...
@Sebastian What is the issue? What does the old file looks like? It doesn't have , as separator?
It looks exactly the same, just not updated. If I save the linked dataset (before importing) on the computer/server/(I unfortunately need to do that) and then try to import it as an Dataframe, the values are not seperated...I have no idea why this works when directly using the URL.
-1

url = 'https://www.ecdc.europa.eu/sites/default/files/documents/Data_response_graphs_2020-10-21.csv'

pd.read_csv(url, sep = ",", header = True)

1 Comment

Welcome to SO. Could you please add a description and code formatting to your answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.