apply方法:
import pandas as pd path = 'score.xlsx' df = pd.read_excel(path) df['理综'] = df['物理']+df['化学']+df['生物'] df.head() def lizong(x): if x['理综'] > 200: return '理科好' elif x['理综'] >100: return '理科及格' else: return '理科差' df['理科情况'] = df.apply(lizong,axis=1) #axis=1表示参数传递按列索引 df['数学'].value_counts() df.to_excel("3.xlsx")
标签:理科,lizong,return,df,理综,添加,方法,pandas From: https://www.cnblogs.com/scholarly/p/17001938.html