def add_featuresgroup groupseq_min = groupVia_Seqmin groupsecond_smallest = groupVia_Seqnsmallest2iloc-1 groupsecond_largest = groupVia_Seqnlargest2iloc-1 groupseq_max = groupVia_Seqmax
可以尝试将group_second_smallestA、group_second_smallestD、group_second_largestA、group_second_largestD的groupby中的'Via_Seq'和'Via_Station_Seq'改为对应的新特征名,即'second_smallest'和'second_largest',也就是:
group_second_smallestA = data.groupby(['TrainIndex', 'second_smallest'])['Arrive_TmS'].nsmallest( 2).reset_index().rename(columns={'Arrive_TmS': 'Second_Arrive_TmS', 'second_smallest': 'Via_Seq'}) group_second_smallestD = data.groupby(['TrainIndex', 'second_smallest'])['Deptr_TmS'].nsmallest( 2).reset_index().rename(columns={'Deptr_TmS': 'Second_Deptr_TmS', 'second_smallest': 'Via_Seq'}) group_second_largestA = data.groupby(['TrainIndex', 'second_largest'])['Arrive_TmS'].nlargest( 2).reset_index().rename(columns={'Arrive_TmS': 'Secondlast_Arrive_TmS', 'second_largest': 'Via_Station_Seq'}) group_second_largestD = data.groupby(['TrainIndex', 'second_largest'])['Deptr_TmS'].nlargest( 2).reset_index().rename(columns={'Deptr_TmS': 'Secondlast_Deptr_TmS', 'second_largest': 'Via_Station_Seq'}
原文地址: https://www.cveoy.top/t/topic/c4sz 著作权归作者所有。请勿转载和采集!