猫史档案馆


精帖!作者想了很久才想出的!快来看看!

用户:RightAboveChilamRightAboveChilam查看:0 回复:2 评论:0 创建时间:2022-11-25T16:35:18


前提是必须要有pandas、numpy、matplotilb.pyplot库!比赛代码qwq全要背

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df1=pd.read_csv('d:\\data.csv')
print(df1)
print('显示缺失的量,缺失的量显示为“TURE”',df1.isnull())
df2=df1.dropna()
print(df2)
df2.to_csv('data.csv',encoding='UTF_8_sig',index=False)
df3=pd.read_csv('d:\\data.csv')
temp=df3[['语文','数学','英语']]
df3['总分']=temp.sum(axis=1)
temp=df3[['总分']]
df3[['总分排名']]=temp.rank(method='min',ascending=False)
print(df3)
print('年级语文平均分%.2f'  %df3['语文'].mean())
chinesepjf=df2.groupby('班别').mean()['语文']
print(chinesepjf)


df2.to_csv('d:\\data.csv',encoding='UTF_8_sig',index=False)
plt.rcParams['font.sans-serif']=['simHei']
plt.rcParams['axes.unicode_minus']=False
x=chinesepjf.index
y=chinesepjf.values
plt.bar(x,y)
plt.show
#条形统计图
plt.bar(x=range(0,len(x)),height=y,align='center',color='yellow')
plt.xlabel('班别')
plt.ylabel('语文平均分')
plt.title('各个班的语文成绩')
plt.show()

#饼图
animals='dogs','cats','tigers','monkeys'
shuliang=[15,30,45,10]
plt.pie(shuliang,labels=animals,autopct='%1.1f%%')
plt.show()

#折线图
x=[2,5,6]
y=[15,26,48]
plt.plot(x,y)
plt.show()


回复

上一页1 页 / 共 1下一页
一朵清云一朵清云

沙发!

点赞0


评论


RightAboveChilamRightAboveChilam

d d d

点赞0


评论