下载文件:
In [1]: import requests
In [2]: url = 'https://assets.publishing.service.gov.uk/government/uploads/syste
...: m/uploads/attachment_data/file/959864/COVID-19-transport-use-statistics.
...: ods'
In [3]: with open('COVID-19-transport-use-statistics.ods', 'wb') as out_file:
...: content = requests.get(url, stream=True).content
...: out_file.write(content)
pip install pandas-ods-reader
然后:
In [4]: from pandas_ods_reader import read_ods
In [5]: df = read_ods('COVID-19-transport-use-statistics.ods', 1)
In [6]: df
Out[6]:
Department for Transport statistics ... unnamed.9
0 https://www.gov.uk/government/statistics/trans... ... None
1 None ... None
2 Use of transport modes: Great Britain, since 1... ... None
3 Figures are percentages of an equivalent day o... ... None
4 None ... Percentage
.. ... ... ...
390 Transport for London Tube and Bus ... None
391 Buses (excl. London) ... None
392 Cycling ... None
393 Any other queries ... None
394 Media enquiries ... None
如果你想用csv,你可以把它保存为csv
df.to_csv('my_data.csv', index=False)