From 620ca920e3bdc9bc462b3c11f8f13612b6bd388b Mon Sep 17 00:00:00 2001 From: hnu202110040409 Date: Tue, 31 May 2022 10:28:02 +0800 Subject: [PATCH] ADD file via upload --- usa epidemic data.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 usa epidemic data.py diff --git a/usa epidemic data.py b/usa epidemic data.py new file mode 100644 index 0000000..7908f73 --- /dev/null +++ b/usa epidemic data.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue May 31 09:36:41 2022 + +@author: Lenovo +""" + +import requests +url = "https://www.bitpush.news/covid19/" +headers = {"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"} +response = requests.get(url, headers=headers) +html = response.text +from lxml import etree +parse = etree.HTMLParser(encoding='utf-8') +doc = etree.HTML(html) +country = doc.xpath('//div[@class="table_container"]//tbody/tr/td/span/text()') +person = doc.xpath('//div[@class="table_container"]//tbody/tr/td[2]/text()') +death = doc.xpath('//div[@class="table_container"]//tbody/tr/td[3]/text()') +death = [x.replace(",", "") for x in death] +message = list(zip(country, person, death)) +message +import csv +with open("content.csv", "w") as f: + w = csv.writer(f) + w.writerows(message) +import pandas as pd +df = pd.read_csv("content.csv", names=["district", "person", "death"], encoding='gb2312') +df = df.drop(range(0,101)) +df=df.sort_values(by='death',ascending=False) +df1=df.head(15) + +import matplotlib.pyplot as plt +%matplotlib inline +plt.rcParams['font.sans-serif'] = ['SimHei'] +plt.rcParams['figure.figsize'] = (10, 5) +x = df1["district"].values +y = df1["death"].values +plt.bar(x, y) +plt.xlabel("地区",fontsize=14) +plt.ylabel("死亡人数",fontsize=14) +plt.show() + + +