Python Forum
How to check multiple columns value within range
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to check multiple columns value within range
#1
Hi all,

The demo is wanted check multiple columns within range(filter out of range row) and pick up other columns.

when chosen one column that can work by between function, but add more columns got an error.

import pandas as pd
df=pd.read_csv(r'log.csv',header=1).drop([0,1])

df1=df['VDD Continuity'].between(-0.8,-0.25,inclusive ='both')
print(df[df1]['DUT_NM_Noise'])
# It is work as well.



df1=df[['VDD Continuity','LR Continuity','DATA Continuity','SCLK Continuity']].astype('float').between(-0.8,-0.25,inclusive ='both')
print(df[df1]['DUT_NM_Noise'])

It doesn't work.
Is there have a good way to handle the issue,thanks!!
Reply
#2
Try this.
import pandas as pd

df = pd.read_csv(r'log.csv', header=1).drop([0, 1])
# Filter rows based on multiple columns
filter_cond = (
    df['VDD Continuity'].between(-0.8, -0.25, inclusive='both') &
    df['LR Continuity'].between(-0.8, -0.25, inclusive='both') &
    df['DATA Continuity'].between(-0.8, -0.25, inclusive='both') &
    df['SCLK Continuity'].between(-0.8, -0.25, inclusive='both')
)

filtered_df = df.loc[filter_cond]
result = filtered_df['DUT_NM_Noise']
print(result)
Reply
#3
It's work, thanks for you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Check DataFrames with different sorting in columns and rows Foxyskippy 0 781 Nov-19-2022, 07:49 AM
Last Post: Foxyskippy
  How to move multiple columns to initial position SriRajesh 4 1,439 Jul-02-2022, 10:34 AM
Last Post: deanhystad
  df column aggregate and group by multiple columns SriRajesh 0 1,051 May-06-2022, 02:26 PM
Last Post: SriRajesh
  Split single column to multiple columns SriRajesh 1 1,339 Jan-07-2022, 06:43 PM
Last Post: jefsummers
  matplotlib x axis range goes over the set range Pedroski55 5 3,228 Nov-21-2021, 08:40 AM
Last Post: paul18fr
  Apply fillna to multiple columns in dataframe rraillon 2 2,454 Aug-05-2021, 01:11 PM
Last Post: rraillon
  Pandas: how to split one row of data to multiple rows and columns in Python GerardMoussendo 4 6,857 Feb-22-2021, 06:51 PM
Last Post: eddywinch82
  How to fill parameter with data from multiple columns CSV file greenpine 1 1,671 Dec-21-2020, 06:50 PM
Last Post: Larz60+
  convert string into multiple columns in python3 VAN 2 2,775 Sep-26-2020, 11:14 PM
Last Post: scidam
  How to melt dataframe multiple columns to one column Mekala 1 2,887 Sep-24-2020, 08:32 PM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020