iode.Scalars.from_frame
- Scalars.from_frame(df: DataFrame)[source]
Copy the pandas DataFrame df into the IODE Scalars database. The scalar names to copy are deduced from the index of the DataFrame.
- Parameters:
- df: DataFrame
pandas DataFrame containing the scalars to copy into the Scalars database. The passed DataFrame should have the following structure:
index: names of the scalars
a column labeled ‘value’: values of the scalars.
a column labeled ‘relax’ (optional): relaxation parameter values of the scalars.
a column labeled ‘std’ (optional): standard deviation values resulting from estimation.
If the DataFrame does not contain a ‘relax’ column, relax values will be all set to 1. If the DataFrame does not contain a ‘std’ column, std values will be all set to \(NA\).
See also
Notes
The index of the passed DataFrame is sorted in alphabetical order before copying to IODE Scalars database.
Examples
>>> from iode import scalars >>> import pandas as pd >>> import numpy as np >>> scalars.clear() >>> len(scalars) 0
>>> # create the pandas DataFrame >>> data = {"alpha_0": [0.9, 1., np.nan], ... "alpha_1": [0.1, 0.8, np.nan], ... "alpha_": [5.5, 0., np.nan], ... "beta_0": [0.9, 1., 0.05246], ... "beta_1": [0.01, 0.8, 0.25687], ... "beta_": [3.6, 0., 0.]} >>> df = pd.DataFrame.from_dict(data, orient='index', dtype="float64", ... columns=["value", "relax", "std"]) >>> # display the pandas series >>> df value relax std alpha_0 0.90 1.0 NaN alpha_1 0.10 0.8 NaN alpha_ 5.50 0.0 NaN beta_0 0.90 1.0 0.05246 beta_1 0.01 0.8 0.25687 beta_ 3.60 0.0 0.00000
>>> # load into the IODE Scalars database >>> scalars.from_frame(df) >>> len(scalars) 6
>>> scalars.names ['alpha_', 'alpha_0', 'alpha_1', 'beta_', 'beta_0', 'beta_1'] >>> df.loc["alpha_1"] value 0.1 relax 0.8 std NaN Name: alpha_1, dtype: float64 >>> scalars["alpha_1"] Scalar(0.1, 0.8, na) >>> df.loc["beta_1"] value 0.01000 relax 0.80000 std 0.25687 Name: beta_1, dtype: float64 >>> scalars["beta_1"] Scalar(0.01, 0.8, 0.25687)