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 41 42 43 44 45 46 47 48 49 50 51 52
| import pandas as pd
data = pd.DataFrame( { "学号": ["19000","19001","19002","19003","19004", "19005","19006","19007","19008","19009"], "姓名": ["Johnny","Mary", "Sara", "Micky","Jerry","Sunny","Sherry","Alice","Nala","Anna"], "程序设计": [88, 75, 95, 85, 58, 78, 56, 68, 73, 63], "体育": [91, 80, 90, 80, 76, 74, 70, 96, 86, 69], "英语": [76, 93, 89, 90, 86, 57, 76, 67, 64, 85], "高数": [67, 85, 91, 78, 89, 64, 67, 70, 91, 93], } )
nData = data[data["英语"] < 60] print(nData)
data["总分"] = data["程序设计"] + data["体育"] + data["英语"] + data["高数"] print(data)
data.loc[data["程序设计"] < 60, "程序设计"] = 60 print(data)
print(data.loc[:, data.columns != "学号"].mean())
data.sort_values(by=["总分", "英语"], ascending=[False, False], inplace=True) print(data)
nData = data[(data["程序设计"] >= 90) & (data["高数"] >= 90)] print(nData)
data["程序设计分级"] = pd.cut( data["程序设计"], [0, 59, 70, 80, 90, 100], labels=["不及格", "及格", "中", "良", "优秀"] ) print(data)
print(data["程序设计分级"].value_counts())
nData = data[(data["英语"] >= 80)] print(nData[["学号", "姓名", "英语", "高数"]])
nData = data[data["姓名"].str.contains("S")] print(nData)
|