新冠疫情数据采集及可视化代码实现
时间: 2023-09-20 14:09:37 浏览: 143
26, -18518, -18501, -18490, -18478, -18463, -18448, -18447以下是一个使用Python实现新冠疫情数据采集及可视化的示例代码:
1. 数据采集部, -18446, -18239, -18237,
-18231, -18220, -18211, -18201分:
```python
import requests
import json
import pandas as pd
# 获取全球新冠疫情数据
url = ', -18184, -18183, -18181, -18012, -17997, -17988, -17970,
https://covid-api.mmediagroup.fr/v1/cases'
response = requests.get(url)
data = json.loads(response.text)
# -17964, -17961, -17950, -17947, -17931, -17928, -17922, 整理数据
df = pd.DataFrame(data).transpose()
df = df[['All', 'abbreviation']]
df = df.rename(columns={'All': -17759, -17752, -17733, -17730,
-17721, -17703, -17701, 'data', 'abbreviation': 'country'})
df.index.name = 'date'
df.to_csv('global_covid_data.csv')
```
2 -17697, -17692, -17683, -17676, -17496, -17487, -17482, -. 数据可视化部分:
```python
import pandas as pd
import matplotlib.pyplot as plt
# 读取数据
df17468,
-17454, -17433, -17427, -17417, -17202, -17185, - = pd.read_csv('global_covid_data.csv', index_col='date', parse_dates=True)
# 绘制全球确诊人数16983, -16970, -16942, -16915, -16733,
-16708, -16706, -趋势图
fig, ax = plt.subplots(figsize=(10, 6))
df['data'].plot(ax=ax)
ax.set_title('16689, -16664, -16657, -16647, -16474, -16470, -16465, -164Global COVID-19 Cases')
ax.set_xlabel('Date')
ax.set_ylabel('Confirmed Cases')
plt.show()
# 绘制各国确诊59, -16452,
-16448, -16433, -16429, -16427, -16423, -164人数地图
import plotly.express as px
fig = px.choropleth(df, locations='country', color='data',
hover_name='country', animation_frame=df.index,
projection='natural earth')
fig.show()
```
这段代码实现19, -16412, -16407, -16403, -16401, -16393,
-16220, -162了从一个API接口获取全球新冠疫情数据,并将数据存储为CSV文件,然后使用Matplotlib绘16, -16212, -16205, -16202, -16187, -16180, -16171, -16169制全球确诊人数趋势图,并使用Plotly绘制各国确诊人数地图。当然,这, -16158, -16155,
-15959, -15958, -15944, -15933, -15920, -15915, -15903, -15889, -15878, -15707, -15701,
-15681只是一个简单的示例,实际的数据采集和可视化过程可能会更加复杂和细致。
阅读全文