You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For those looking to use the model output in other software (e.g., for plotting), it can be helpful to be able to put three dimensional objects into a DataFrame as panel dataset.
We could add a utility to utils.py to simplify this. The code could be something like
defD3_to_df(tpi_vars, var="c_path", start_year=2025):
data=tpi_vars[var]
# First, get the dimensions of your arrayT, S, J=data.shape# Create index values for each dimensionidx_t= [f'{start_year+i}'foriinrange(T)] # You can customize these labelsidx_s= [f'{i}'foriinrange(S)]
idx_j= [f'{i}'foriinrange(J)]
# Create MultiIndex from the first two dimensionsmulti_idx=pd.MultiIndex.from_product([idx_t, idx_s], names=['Year', 'Age'])
# Reshape the 3D array to 2Dreshaped_data=data.reshape(T*S, J)
# Create the DataFrame with MultiIndexdf=pd.DataFrame(reshaped_data, index=multi_idx, columns=idx_j)
returndf
For those looking to use the model output in other software (e.g., for plotting), it can be helpful to be able to put three dimensional objects into a DataFrame as panel dataset.
We could add a utility to
utils.py
to simplify this. The code could be something likeThen use this function with:
The text was updated successfully, but these errors were encountered: