Using local variables with multiple assignments with pandas eval function

前端 未结 1 914
刺人心
刺人心 2020-12-20 02:37

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

相关标签:
1条回答
  • 2020-12-20 02:56

    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.

    0 讨论(0)
提交回复
热议问题