
为统计分析城市A全年各月份PM2.5的月平均浓度(当月的日平均浓度的平均值),编写Python程序。请回答下列问题:
(l)定义pmday函数,功能为:读取某天的CSV文件,返回城市A当天PM2.5的日平均浓度。函数代码如下,划线处应填入的代码为<单选,填字母)。
A.df['类型']= ='PM2.5 B.df['类型'=='PM2.5']
C.df[df['类型']]= ='PM2.5' D.df[df['类型']=='PM2.5']
import pandas as pd
def pmday(dayfile):
df=pd read_csv(dayfile) #读取文件dayfile中的数据
df=
return df['城市A'].mean() #返回城市A当天PM2.5的日平均浓度
(2)统计城市A各月份PM2.5的月平均浓度并绘制线型图。部分Python程序如下,请在划线处填写合适的代码:
import matplothb. pyplot as plt
def tstr(t):
if t<l0:
retrun '0'+str(t)
else:
retrun str(t)
pm=[0]*12
mdays=[31.28.31.30.31.30.31.31.30.31.30.31]
for m in range(12):
sm=0
mstr=tstr(m+1)
for d in range(①
dstr=tstr(d+l)
day file='202l'+mstr+ dstr+'.csv'
sd=pmday(dayfile)
②
pm[m]=sm/mdays[m]
x=[1,2,3,4,5,6,7,8,9,10,11,12]
y=③
plt. plot(x,y) #绘制线型图
#设置绘图参数,显示如图c所示线型图,代码略

(3)城市A 2021年PM2.5年平均浓度为34.6微克/立方米。由图c可知,城市A 2021年PM2.5月平均浓度超过年平均浓度的月份共

同类型试题

y = sin x, x∈R, y∈[–1,1],周期为2π,函数图像以 x = (π/2) + kπ 为对称轴
y = arcsin x, x∈[–1,1], y∈[–π/2,π/2]
sin x = 0 ←→ arcsin x = 0
sin x = 1/2 ←→ arcsin x = π/6
sin x = √2/2 ←→ arcsin x = π/4
sin x = 1 ←→ arcsin x = π/2


y = sin x, x∈R, y∈[–1,1],周期为2π,函数图像以 x = (π/2) + kπ 为对称轴
y = arcsin x, x∈[–1,1], y∈[–π/2,π/2]
sin x = 0 ←→ arcsin x = 0
sin x = 1/2 ←→ arcsin x = π/6
sin x = √2/2 ←→ arcsin x = π/4
sin x = 1 ←→ arcsin x = π/2

