Skip to content
Browse files

add parameter reverse to sort

  • Loading branch information...
sdpython committed Sep 3, 2017
1 parent 44c9211 commit f40ec6bff852c5c98a671eff5558981bc4de1586
Showing with 4 additions and 3 deletions.
  1. +4 −3 src/pyensae/pandas_helper/
@@ -18,19 +18,20 @@ def __init__(self, *args, **kwargs):
pandas.DataFrame.__init__(self, *args, **kwargs)

def sort(self, function_sort):
def sort(self, function_sort, reverse=False):
Sort rows based on the value returned by *function_sort*.
@param function_sort lambda function
@param reverse reverse order
The function creates a column ``__key__`` an removes it later.
if "__key__" in self.columns:
raise ValueError(
"__key__ cannot be used in the original dataframe.")
self["__key__"] = self.apply(lambda row: function_sort(row), axis=1)
self.sort_values("__key__", inplace=True)
self.sort_values("__key__", inplace=True, ascending=not reverse)
self.drop("__key__", inplace=True, axis=1)

def fgroupby(self, function_key, function_values, columns=None,
@@ -105,7 +106,7 @@ def fgroupby(self, function_key, function_values, columns=None,
gr = cp.groupby("__key__", as_index=False).agg(aggs)
gr.columns = [rep.get(_, _) for _ in gr.columns]
gr = gr.drop("__key__", axis=1)
return gr
return TableFormula(gr)

def add_column_index(self, index):

0 comments on commit f40ec6b

Please sign in to comment.
You can’t perform that action at this time.