图 a
df = pd.read_excel("历年世界杯各国数据.xlsx")
print(df)
则方框处可选代码是 (按数据处理先后顺序填序号)。
①df = df.groupby("所属大洲")
②df = df[:3]
③df = df.sort_values("进球数", ascending=False)
④df = df[df["所属大洲"]=="非洲"]
⑤df = df["非洲"]
图 b
df1 = pd.read_excel("历年世界杯各国数据.xlsx")
df2 = pd.read_excel("英格兰.xlsx")
for i in range(len(df1)):
if df1.at[i, "球队"]=="英格兰":
break
for line in df2.values:
goal = line[2]; lost = line[3]
if goal>lost:
df1.at[index, "胜"] += 1
elif
goal<lost:
df1.at[index, "负"] += 1
else:
df1.at[index, "平"] += 1
df1.at[index, "进球数"] += goal
df1.at[index, "失球数"] += lost
df1.at[index, "净胜球"] += goal - lost
df1.to_excel("(new)历年世界杯各国数据.xlsx", index=False) #去除索引保存文件
图 c
df1 = pd.read_excel("(new)历年世界杯各国数据.xlsx")
df1 = df1.sort_values("进球数",ascending=False) #①
df1 = df1[df1["所属大洲"]=="南美洲"]
df1 = df1[["球队", "进球数"]] #②
df1.plot.bar(x="球队", y="进球数") #③
plt.show() #④