|
|
@ -9,13 +9,9 @@ encoding='utf-8'
|
|
|
|
parse = etree.HTMLParser(encoding='utf-8')
|
|
|
|
parse = etree.HTMLParser(encoding='utf-8')
|
|
|
|
doc = etree.HTML(html)
|
|
|
|
doc = etree.HTML(html)
|
|
|
|
states = doc.xpath('//div[@class="table_container"]//tbody/tr/td/span/text()')
|
|
|
|
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()')
|
|
|
|
person = doc.xpath('//div[@class="table_container"]//tbody/tr/td[2]/text()')
|
|
|
|
print(person)
|
|
|
|
|
|
|
|
person = [x.replace(",", "") for x in person]
|
|
|
|
person = [x.replace(",", "") for x in person]
|
|
|
|
print(person)
|
|
|
|
|
|
|
|
death = doc.xpath('//div[@class="table_container"]//tbody/tr/td[3]/text()')
|
|
|
|
death = doc.xpath('//div[@class="table_container"]//tbody/tr/td[3]/text()')
|
|
|
|
print(death)
|
|
|
|
|
|
|
|
death = [x.replace(",", "") for x in death]
|
|
|
|
death = [x.replace(",", "") for x in death]
|
|
|
|
message = list(zip(states, person, death))
|
|
|
|
message = list(zip(states, person, death))
|
|
|
|
import csv
|
|
|
|
import csv
|
|
|
@ -25,7 +21,7 @@ with open("content.csv", "w") as f:
|
|
|
|
print(w)
|
|
|
|
print(w)
|
|
|
|
import pandas as pd
|
|
|
|
import pandas as pd
|
|
|
|
print("content.csv")
|
|
|
|
print("content.csv")
|
|
|
|
#读取数据
|
|
|
|
#读
|
|
|
|
df = pd.read_csv("content.csv", names=["states", "person", "death"])
|
|
|
|
df = pd.read_csv("content.csv", names=["states", "person", "death"])
|
|
|
|
df.head()
|
|
|
|
df.head()
|
|
|
|
print(df)
|
|
|
|
print(df)
|
|
|
@ -38,7 +34,6 @@ df=df.iloc[0:15]
|
|
|
|
print(df)
|
|
|
|
print(df)
|
|
|
|
|
|
|
|
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
|
|
|
|
|
plt.rcParams['font.sans-serif'] = ['SimHei']
|
|
|
|
plt.rcParams['font.sans-serif'] = ['SimHei']
|
|
|
|
plt.rcParams['figure.figsize'] = (10, 5)
|
|
|
|
plt.rcParams['figure.figsize'] = (10, 5)
|
|
|
|
x = df["states"].values
|
|
|
|
x = df["states"].values
|
|
|
@ -47,3 +42,4 @@ plt.bar(x, y)
|
|
|
|
plt.xlabel("states")
|
|
|
|
plt.xlabel("states")
|
|
|
|
plt.ylabel("death")
|
|
|
|
plt.ylabel("death")
|
|
|
|
plt.show()
|
|
|
|
plt.show()
|
|
|
|
|
|
|
|
|
|
|
|