I want to get a subset of a dataframe based upon multiple conditions with the number of conditions I pass it variable.
I have seen similar answers with multiple conditions(Select rows from a DataFrame based on values in a column in pandas) , but none that allow to pass less variables.
I have tried using: c=None, c=True, c=all, but it always evaluates to false
def Subset (df, a=None, b=None, c=True):
temp=df.loc[(df['a'] == a) & (df['b'] == b) & (df['c'] == c)]
return (temp)
if I evaluate:
Subset=Subset(df=Table, a=350, b=300)
I get an empty dataframe
while if I use the function:
def Try(df, a=None, b=None):
temp=df.loc[(df['a'] == a) & (df['b'] == b)]
return (temp)
I get a dataframe with 10 rows.
To answer Yaakov Bressler's comment I am giving more information: My dataframe looks like this:
files,Names,Curve Type,Thickness,Temperature,Number,Iteration,leak,start,stop,Vth,F_E_M,on/off
Output [(1) _250-300-G21_]0.csv,250-300-G21,Output,250,300,G21,0,True,,,,,
Output [(1) _250-300-G22_]0.csv,250-300-G22,Output,250,300,G22,0,False,,,,,
Transfer lin [(1) _250-300-G21_;]0.csv,250-300-G21,Transfer lin,250,300,G21,0,True,,,,,
the first column are the filenames. the other columns are data about the transitor that file represents.
I want to create a subset of this file representing a single transistor, defined by: ( Curve Type,Thickness,Temperature,Number ) or of a single chip : (Curve Type,Thickness,Temperature).
This is so that I can import them and do plots/analysis.