[Python] Pandas's .gt() and .lt() not working when chained together

Discussão em 'Python' iniciado por Stack, Abril 20, 2025.

  1. Stack

    Stack Membro Participativo

    I'm playing around with the pipe | and ampersand & operators, as well as the .gt() and .lt() built-in functions to see how they work together.

    I'm looking at a column in a DataFrame with values from 0.00 to 1.00.

    I can use the >, <, and & operators together and find no problem, same with using .gt(), .lt(), and &. However, if I try to chain .gt().lt() it gives another result.

    In my example I'm using .gt(0.7).lt(0.9), but this yields values <=0.7. If I change the order to .lt(0.9).gt(0.7), I get values <=0.9.

    I can always just write it like this df['column'].gt(0.7)&df['column'].lt(0.9), just wondering if there's a way of chaining .gt().lt()

    Continue reading...

Compartilhe esta Página