Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

change order of cost type columns to match position in chain #155

Merged
merged 2 commits into from
Dec 5, 2023
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
35 changes: 34 additions & 1 deletion app/ptxboa_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,40 @@ def aggregate_costs(
# calculate total costs:
res["Total"] = res.sum(axis=1)

return res
return sort_cost_type_columns_by_position_in_chain(res)


def sort_cost_type_columns_by_position_in_chain(df):
"""Change cost type column order to match the occurrence in a chain.

This is necessary for the order of the colors in the stacked barplots (GH #150).

Parameters
----------
df : pd.DataFrame
columns need to be in 'cost_type_order'

Returns
-------
pd.DataFrame
same data with changed order of columns.
"""
#
cost_type_order = [
"Electricity generation",
"Electrolysis",
"Electricity and H2 storage",
"Derivate production",
"Heat",
"Water",
"Carbon",
"Transportation (Pipeline)",
"Transportation (Ship)",
"Total",
]
assert [c in cost_type_order for c in df.columns]
cols = [c for c in cost_type_order if c in df.columns]
return df[cols]


def subset_and_pivot_input_data(
Expand Down