we have a data frame containing four features of dtype; num, num, object and float respectively.
And i want to filter data with this condition:
1. f['g']=< 53
2. f['h'] minmax (1,67) ..the value should be between the user-specified value.
3. f['k]=='y'
4.f['l'] minmax(22,77) ..the value should be between the user-specified value.
I want to write a function named 'Datafilter' which can do multiple filtering and also we should be able to add filters and change conditions according to our future requirement.
Here is a Dataframe.
f= pd.DataFrame({'g':[1,2,3,45,33,57,23,53,56,79],
'h':[12,344,5,78,98,95,43,56,32,23],
'k':['y','y','n','y','n','n','y','n','y','n'],
'l':[1.0,2.0,22.0,244.0,43.0,34.0,78.0,5.0,77.0,97.0]})
I am a beginner so I was able to do it by applying one filter at a time.
>>>[IN] t=f.copy()
>>>[IN] t=t[ t['g']<= 53]
>>>[IN] t=t[t['h'].between(12,98) & t['l'].between(2.0,78.0)]
>>>[IN] t=t[t['k']=='n']
>>>[IN] print(t)
>>>[OT]
g h k l
4 33 98 n 43.0
7 53 56 n 5.0
the function should be generic i.e. reusable and should able to handle additional filters as well, in the future.