Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Create sort argument do a bar graph #196

Merged
merged 1 commit into from
Mar 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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