apply函数针对dataframe的每一行进行运行较为方便 案例一:把日期修改为季度 1:借用for函数,很费时 for i in range(len(data)-1): print(i) data.loc[data.index==i,'quarter_decison']=str(data.iloc[i]['time_decision_at'].year)+str('-Q')+str(data.iloc[i]['time_decision_at'].quarter) 2:借用apply函数,方便,快捷 #日期季度的获取 data['quarter_decison_2']=data.apply(lambda x:str(x['time_decision_at'].year)+str('-Q')+str(x['time_decision_at'].quarter),axis=1) 案例二:两个指标函数的case when 1:借用for函数,相当费时 for i in range(len(tot_2019_lo.index)): print(i) if (tot_2019_lo.iloc[i]['a11']>=7) & (tot_2019_lo.iloc[i]['d1&#