我有一个很简单的问题:我尝试将以下数据读入数据框https://www.ecdc.europa.eu/en/publications-data/download-data-response-measures-covid-19
如果我使用以下代码,则输出的格式不符合我的期望,因为CSV不是“分隔”的:
dmeasures = pd.read_csv('file.csv',sep=",",header=0,)
print (dmeasures)
有什么主意我的错误是分隔符吗?
答案 0 :(得分:2)
您可以直接从URL读取CSV:
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)
打印:
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]
答案 1 :(得分:-1)
url ='https://www.ecdc.europa.eu/sites/default/files/documents/Data_response_graphs_2020-10-21.csv'
pd.read_csv(url,sep =“,”,标头= True)