selecting rows based on multiple column values in pandas dataframe

前端 未结 4 714
梦如初夏
梦如初夏 2021-02-12 09:41

I have a pandas DataFrame df:

import pandas as pd

data = {\"Name\": [\"AAAA\", \"BBBB\"],
        \"C1\": [25, 12],
              


        
4条回答
  •  野性不改
    2021-02-12 10:20

    I think below should do it, but its elegance is up for debate.

    new_df = old_df[((old_df['C1'] > 0) & (old_df['C1'] < 20)) & ((old_df['C2'] > 0) & (old_df['C2'] < 20)) & ((old_df['C3'] > 0) & (old_df['C3'] < 20))]
    

提交回复
热议问题