Skip to content

Commit

Permalink
Merge pull request #196 from guilecardoso/patch-1
Browse files Browse the repository at this point in the history
Create sort argument do a bar graph
  • Loading branch information
adamerose authored Mar 16, 2022
2 parents bc4a8c7 + a0e963e commit e71a97c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pandasgui/jotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def bar(data_frame: DataFrame,
facet_col: ColumnName = None,
# Custom args
aggregation: Literal['mean', 'median', 'min', 'max', 'sum', None] = 'mean',
sort: Literal['asc', 'desc', None] = 'desc',
**kwargs) -> Figure:
# Create list of key columns
key_cols = [val for val in [x, color, facet_row, facet_col] if val is not None]
Expand All @@ -136,6 +137,12 @@ def bar(data_frame: DataFrame,
else:
# Only need to sort here because aggregation already sorts
data_frame = data_frame.sort_values(key_cols)

if sort is not None:
if sort == 'asc':
data_frame = data_frame.sort_values(y, ascending=True)
else:
data_frame = data_frame.sort_values(y, ascending=False)

fig = px.bar(data_frame=data_frame,
x=x,
Expand Down

0 comments on commit e71a97c

Please sign in to comment.