From 98a7bcd8c6c5718960601ffe527a80a80b60a4ca Mon Sep 17 00:00:00 2001 From: Greg <11791585+elphick@users.noreply.github.com> Date: Tue, 5 Nov 2024 21:04:41 +0800 Subject: [PATCH] fs.to_dataframe column order fix #2 --- elphick/geomet/flowsheet/flowsheet.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/elphick/geomet/flowsheet/flowsheet.py b/elphick/geomet/flowsheet/flowsheet.py index 492a924..1073a16 100644 --- a/elphick/geomet/flowsheet/flowsheet.py +++ b/elphick/geomet/flowsheet/flowsheet.py @@ -708,8 +708,9 @@ def to_dataframe(self, stream_names: Optional[list[str]] = None, tidy: bool = Tr results: pd.DataFrame = pd.concat(chunks, axis='index').set_index('name', append=True) if not tidy: # wide format - results = results.unstack(level='name').swaplevel(axis=1) - results.columns = [f'{col[0]}_{col[1]}' for col in results.columns] + results = results.unstack(level='name', sort=False) + results.columns = [f'{name}_{attr}' for name in results.columns.levels[1] for attr in + results.columns.levels[0]] return results