pandas的reindex功能挺好用,记录一下。
数据只列出一部分吧。
#---------------------------------------------------------#
#---- * reindex命令 * ----#
#---------------------------------------------------------#
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_json( '{"nianji":{"5742":"一年级","1469":"一年级","7212":"一年级","3923":"三年级","5718":"三年级","6365":"三年级","443":"中班","451":"中班","506":"中班","1741":"二年级","2011":"二年级","6605":"二年级","3737":"五年级","4340":"五年级","4297":"五年级","8056":"初一","8036":"初一","8147":"初一","8444":"初三","8275":"初三","8343":"初三","8548":"初二","8561":"初二","8562":"初二","8637":"初四","8714":"初四","8709":"初四","8018":"四年级","4628":"四年级","6240":"四年级","509":"大班","521":"大班","878":"大班","914":"小班","614":"小班","575":"小班","639":"托班","635":"托班","642":"托班"},"right":{"5742":5.0,"1469":4.6,"7212":5.0,"3923":5.0,"5718":5.0,"6365":4.8,"443":5.0,"451":5.0,"506":5.0,"1741":5.0,"2011":5.0,"6605":5.0,"3737":4.2,"4340":5.0,"4297":4.1,"8056":4.3,"8036":4.6,"8147":5.0,"8444":4.3,"8275":4.0,"8343":4.0,"8548":5.0,"8561":4.7,"8562":4.7,"8637":4.4,"8714":4.1,"8709":4.4,"8018":5.0,"4628":5.0,"6240":4.7,"509":4.9,"521":5.0,"878":5.0,"914":4.9,"614":4.8,"575":4.9,"639":4.8,"635":4.9,"642":4.8}}')
score_of_everyGrade = pd.pivot_table(index = 'nianji', data=df)['right']
score_of_everyGrade
list_of_grade = [ '托班', '小班', '中班', '大班', '一年级', '二年级', '三年级' ,'四年级', '五年级', '初一', '初三', '初二', '初四' ]
to_img = score_of_everyGrade.reindex(list_of_grade)
plt.plot(to_img)
plt.xticks(rotation=45)
?
|