PM2.5随时间的变化情况
import pandas as pd
from matplotlib import pyplot as plt
p1 = pd.read_csv("./PM2.5/BeijingPM20100101_20151231.csv")
time_data = pd.PeriodIndex(year=p1["year"], month=p1["month"], day=p1["day"], hour=p1["hour"], freq="H")
p1["date"] = time_data
p1.set_index("date", inplace=True)
p1 = p1.resample("7D").mean()
us_data = p1["PM_US Post"]
china_data = p1["PM_Nongzhanguan"]
us_index = [i.strftime("%Y-%m-%d") for i in us_data.index]
china_index = [i.strftime("%Y-%m-%d") for i in china_data.index]
us_values = us_data.values
china_values = china_data.values
plt.figure(figsize=(20, 8), dpi=80)
plt.plot(us_index, us_values, label="US Post")
plt.plot(china_index, china_values, label="China Post")
plt.xticks(range(0, len(china_index), 10), china_index[::10], rotation=45)
plt.legend(loc="best")
plt.show()
|