def select_n_frame(frame, columns, n, method, keep):
 from pandas.core.series import Series
 if (not is_list_like(columns)):
  columns = [columns]
 columns = list(columns)
 ser = getattr(frame[columns[0]], method)(n, keep=keep)
 if isinstance(ser, Series):
  ser = ser.to_frame()
 return ser.merge(frame, on=columns[0], left_index=True)[frame.columns]

def select_n_frame ( frame , columns , n , method , keep ) : from pandas . core . series import Series if ( not is_list_like ( columns ) ) : columns = [ columns ] columns = list ( columns ) ser = getattr ( frame [ columns [ 0 ] ] , method ) ( n , keep = keep ) if isinstance ( ser , Series ) : ser = ser . to_frame ( ) return ser . merge ( frame , on = columns [ 0 ] , left_index = True ) [ frame . columns ]
implement n largest/smallest for pandas dataframe parameters frame : pandas .