Allow passing df that has no idxmax or idxmin
This commit is contained in:
parent
90168e4f1f
commit
d617e50cda
1 changed files with 10 additions and 2 deletions
|
|
@ -179,7 +179,15 @@ def find_neighbours(value, df, colname, start=0, end=-1):
|
||||||
lower_df = df[df[colname] < value][colname]
|
lower_df = df[df[colname] < value][colname]
|
||||||
upper_df = df[df[colname] > value][colname]
|
upper_df = df[df[colname] > value][colname]
|
||||||
|
|
||||||
lowerneighbour_ind = lower_df.idxmax()
|
|
||||||
upperneighbour_ind = upper_df.idxmin()
|
if not lower_df.empty:
|
||||||
|
lowerneighbour_ind = lower_df.idxmax()
|
||||||
|
else:
|
||||||
|
lowerneighbour_ind = np.nan
|
||||||
|
|
||||||
|
if not upper_df.empty:
|
||||||
|
upperneighbour_ind = upper_df.idxmin()
|
||||||
|
else:
|
||||||
|
upperneighbour_ind = np.nan
|
||||||
|
|
||||||
return [lowerneighbour_ind, upperneighbour_ind]
|
return [lowerneighbour_ind, upperneighbour_ind]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue