I have created a pandas data frame and would like to filter the data based on certain boolean logic. Essentially what I'd like to do is closer to excels' index match function than to simple filtering. I have researched a lot of other threads.
When I apply my filter, the data frame returns zero true values. Why are zero true values being returned when I have been flexible with my logic? and;
If I introduced a 5th column, say column
'D', withrandom.randomint(100-1000,100), what logic would I use to conditionally find the maximum values only for columnD? I.e. Can I force a data frame to return the highest true values only from a certain column, in the event that multiple true values are returned?
Advice much appreciated. Thank you in advance.
import pandas as pd
df = pd.DataFrame({
'Step': [1,1,1,1,1,1,2,2,2,2,2,2],
'A': [4,5,6,7,4,5,6,7,4,5,6,7],
'B': [10,20,30,40,10,20,30,40,10,20,30,40],
'C': [0,0.5,1,1.5,2,2.5,0,0.5,1,1.5,2.0,2.5]
})
columns = ['Step','A','B','C']
df=df[columns]
new_df=df[(df.Step == 1) & (df.A == 4|5|6|7) & (df.B == 10|20|30|40)]
new_df
2.? Do you need one largest value?