Matplotlib可能是Python的事实数据可视化库,但它并不总是最漂亮的。在本文中,我们将探讨如何将单调的默认Matplotlib图变成漂亮的数据可视化。我们将探索COVID-19数据,以了解该病毒如何在不同国家传播(我们只是针对数据进行分析不对任何做出评价)。
首先加载数据
我们将使用来Github存储库中的数据,这个存储库每天会自动更新各国数据。我们将根据URL将数据加载到Pandas的数据框中,以便每天自动为我们更新。
# Section 1 - Loading our Librariesimport pandas as pdimport matplotlib.pyplot as pltfrom matplotlib.dates import DateFormatterimport matplotlib.ticker as ticker%matplotlib inline #if you're working in a Jupyter notebook# Section 2 - Loading and Selecting Datadf = pd.read_csv('https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv', parse_dates=['Date'])countries = ['Canada', 'Germany', 'United Kingdom', 'US', 'France', 'China']df = df[df['Country'].isin(countries)]# Section 3 - Creating a Summary Columndf['Cases'] = df[['Confirmed', 'Recovered', 'Deaths']].sum(axis=1)