I have a dataframe with a column full of expressions: pd.Series("A + B", "B + C", ...)
it’s really long, so I would like to find a vectorized way to eval every expression with a local dictionary {"A": 5, "B": -2.1, ... }
.
I have tried
pd.eval(df["expressions"], local_dict=dict_all_values)
but it does not seem to work, because it returns 101 values, but the expressions are 21656.
That is not vectorized, but perhaps it suffices:
# s is the series; d the dictionary
s.map(lambda expr: eval(expr, {}, d))