From b8b18db3071e943d7e902738c7d2f9ba1a567a64 Mon Sep 17 00:00:00 2001 From: hnu202111020218 Date: Fri, 31 Dec 2021 21:11:52 +0800 Subject: [PATCH] Update README.md --- README.md | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cfe1150..40a859e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,49 @@ -# 1 +import requests +from lxml import etree +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 +#print(html) +parse = etree.HTMLParser(encoding='utf-8') +doc = etree.HTML(html) +#states +states = doc.xpath('//div[@class="table_container"]//tbody/tr/td/span/text()') +print(states) +person = doc.xpath('//div[@class="table_container"]//tbody/tr/td[2]/text()') +print(person) +person = [x.replace(",", "") for x in person] +print(person) +death = doc.xpath('//div[@class="table_container"]//tbody/tr/td[3]/text()') +print(death) +death = [x.replace(",", "") for x in death] +message = list(zip(states, person, death)) +import csv +with open("content.csv", "w") as f: + a = csv.writer(f) + a.writerows(message) +import pandas as pd + +#读取数据 +df = pd.read_csv("content.csv", names=["states", "person", "death"],encoding = 'gb2312') +df.head() +print(df) +for i in range(101): + df.drop([i],inplace=True) +print(df) +df.sort_values(by=['person'],ascending=False) +print(df) +df=df.iloc[0:158] +print(df) +import matplotlib.pyplot as plt +plt.rcParams['font.sans-serif'] = ['SimHei'] +plt.rcParams['figure.figsize'] = (80,50) +x = df["states"].values +y = df['person'].values +plt.bar(x, y) +plt.xlabel("states") +plt.ylabel("person") +plt.show()