Skip to content

Commit

Permalink
#359 Reorder columns model_run -> timestep -> decision
Browse files Browse the repository at this point in the history
  • Loading branch information
fcooper8472 committed May 1, 2019
1 parent f71b570 commit 844fb8f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/smif/data_layer/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,28 @@ def read(self,

results = pd.concat(list_of_df, keys=names_of_df, names=['model_run']).reset_index()

# Unpack the timestep_decision tuples into individual columns and return
# Unpack the timestep_decision tuples into individual columns and drop the combined
results[['timestep', 'decision']] = pd.DataFrame(results['timestep_decision'].tolist(),
index=results.index)

return results.drop(columns=['timestep_decision'])
results = results.drop(columns=['timestep_decision'])

# Rename the output columns to include units
renamed_cols = dict()
for key, val in self._output_units.items():
renamed_cols[key] = '{}_({})'.format(key, val)
results = results.rename(index=str, columns=renamed_cols)

# Now reorder the columns. Want model_run then timestep then decision
cols = results.columns.tolist()

assert (cols[0] == 'model_run')
cols.insert(1, cols.pop(cols.index('timestep')))
cols.insert(2, cols.pop(cols.index('decision')))
assert(cols[0:3] == ['model_run', 'timestep', 'decision'])

return results[cols]

def get_units(self, output_name: str):
""" Return the units of a given output.
Expand Down

0 comments on commit 844fb8f

Please sign in to comment.