Deleting rows based on multiple conditions Python Pandas

前端 未结 1 792
不知归路
不知归路 2020-12-25 14:32

I want to delete rows when a few conditions are met:

For instance, a random DataFrame is generated:

import pandas as pd
import numpy as np
df = pd.Da         


        
相关标签:
1条回答
  • 2020-12-25 15:14

    For reasons that aren't 100% clear to me, pandas plays nice with the bitwise logical operators | and &, but not the boolean ones or and and.

    Try this instead:

    df = df[(df.one > 0) | (df.two > 0) | (df.three > 0) & (df.four < 1)]
    
    0 讨论(0)
提交回复
热议问题