How to ignore nan values in a dataframe

Viewed 856

I'm trying to check if my last close is higher (or lower) then the support or resistince an my dataframe. The problem is that i have a lot of nan values. How can i ignore those values and just check the last integer value of the colum? below just a short line of code to check if the close is below the support. I have added an picture of my dataframe.

df["Close"][-1] < df["Support"][1] and df["Open"][1] < df["Support"][1]:

enter image description here

1 Answers

You can dropna() before indexing with iloc:

close_condition = df["Close"].dropna().iloc[-1] < df["Support"].dropna().iloc[0]
open_condition = df["Open"].dropna().iloc[0] < df["Support"].dropna().iloc[0]

if close_condition and open_condition:
    ...
Related