1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| import numpy as np import pandas as pd
stu_names = ["胡歌","林更新","金世佳","丑娟"] courses = ['语文', '数学', '英语', 'Python', '体育'] data = np.array([[87., 74., 98., 84., np.nan],[79., 69., 61., 99., np.nan],[84., 84., 94., 66., np.nan],[90., 60., 72., 90., np.nan]]) cj = pd.DataFrame(data,index=stu_names,columns=courses) cj.to_csv('work1.csv',header=True,index=True)
ele_names = ["胡歌","林更新","金世佳","丑娟"] ele_courses = ['统计学', '日语'] ele_data = np.array([[85., np.nan],[np.nan, 69.],[np.nan, 95.],[80., np.nan]]) xx = pd.DataFrame(ele_data,index=ele_names,columns=ele_courses) xx.to_csv('work2.csv',header=True,index=True)
r1 = pd.read_csv('./work1.csv',index_col=0) r2 = pd.read_csv('./work2.csv',index_col=0)
del r1['体育']
r1[r2.columns[0]] = r2[r2.columns[0]] r1[r2.columns[1]] = r2[r2.columns[1]]
r1['总成绩'] = r1.sum(axis=1)
r1.to_csv('total.csv',index=True,header=True) r1.to_excel('total.xlsx',index=True,header=True)
|