I want to select some rows with multiple conditions. I would like to even if one of the conditions was true then that row was selected.
def obtain(x):
mask = (x['EucDistPoint'] >= x['EucDistPoint'].mean()) | (x['CRS'] >=
x['CRS'].mean()) | (x['CRC'] >= x['CRC'].mean())
selected = x.loc[mask]
return selected
selected = data.groupby('MMSI').apply(obtain)
I want the output row to have at least one of the conditions but in output, I have the rows that haven't any of these conditions.
I've applied :
def obtain(x):
mask = (x.EucDistPoint >= x.EucDistPoint.mean()) |\
(x.CRS >= x.CRS.mean()) | (x.CRC >= x.CRC.mean())
return x[mask]
selected = data.groupby('MMSI').apply(obtain)
but when I want to check the output I use this:
selected[selected['MMSI']==210161000].min()
but the output is like this:
MMSI 210161000
BaseDateTime 2017-02-01 08:54:35
LAT 34.2080
LON -125.9994
SOG 1.1000
COG -194.3000
CRS 0.0000
CRC 0.0000
X 230030.4090
Y 3789274.2135
EucDistPoint 0.0000
HaverDistPoint 0.0000
dtype: object
and this is wrong because the minimum of CRS and CRC and EucDistPoint are 0.0022, 0.0446 and 551.887