Skip to content Skip to sidebar Skip to footer

Using Local Variables With Multiple Assignments With Pandas Eval Function

The pandas help file says (for eval): As a convenience, multiple assignments can be performed by using a multi-line string. However, I'm finding that doesn't work with variables (u

Solution 1:

I can confirm that the local variables appear to only work on the first line of a multi line eval expression. A possible work around:

df_price.eval("""mult = @mult
              op = op * mult
              cl = cl * mult
              hi = hi * mult
              lo = lo * mult""", inplace = True)

This does however have the side effect of creating an extra column.

Update:

I have submitted a Pull Request with a fix for this issue.


Post a Comment for "Using Local Variables With Multiple Assignments With Pandas Eval Function"