1.如何在describe 函数中增加diff(range) 和unique 统计量,封装成函数。 para['uniCount'] 写的有问题 运行为空 para = dfpartable.groupby(['Par'],as_index=True)['Value'].describe(percentiles=[.1, .9],include='all')#.sort_values(by = ['Par'],ascending= True) para = para.reset_index() para['uniCount'] = dfpartable.groupby('Par', as_index=True).apply(lambda x: x.Value.nunique())## **paraStep['uniCount'] = dfpartable.groupby(['Par','Step'], as_index=True).nunique() para['Diff'] = dfpartable.groupby('Par')['Value'].transform(lambda x: x.diff())#df.shift()-df 后一个数减去前一个数 ## ** para['Diff'][0] = 0 ## ** #df_2['diff'] = df_2.sort_values(by='DATETIME').groupby('ID3')['DATETIME'].transform(lambda x: x.diff())
para['range'] = para['max']-para['min']
para['Tag'] = "" #df['Tag'] = float('nan')
para.loc[(para['range']/para['mean']<0.1) | (para['uniCount']<6),'Tag']= "3_Stable"
para.loc[(para['max']== para['min']),'Tag'] = "2_Single"
para.loc[(para['max']==0) & (para['min']==0),'Tag'] = "1_0"