Fix assignment to use loc.

For assigning a value to selected rows (a subset), regular slicing using [] produces a KeyError.
communication
junos 2021-08-11 14:53:59 +02:00
parent a06ad0800f
commit a2180aee54
1 changed files with 2 additions and 2 deletions

View File

@ -256,9 +256,9 @@ def clean_up_esm(df_esm_preprocessed: pd.DataFrame) -> pd.DataFrame:
ESM.ESM_TYPE.get("scale"),
ESM.ESM_TYPE.get("number"),
]
df_esm_clean[df_esm_clean["esm_type"].isin(esm_type_numeric)] = df_esm_clean[
df_esm_clean.loc[
df_esm_clean["esm_type"].isin(esm_type_numeric)
].assign(
] = df_esm_clean.loc[df_esm_clean["esm_type"].isin(esm_type_numeric)].assign(
esm_user_answer_numeric=lambda x: x.esm_user_answer.str.slice(stop=1).astype(
int
)