'if condition not meet, leave blank python code

how should we write the code that tell python to leave empty cell in dataframe when the condition is not meet?

I tries " " like excel but it does not work. I tried 'space' also not work either.

eg. np.where((df['Adj Close']> df['signal']), 1, 'what should be the sign here? ' )

Thanks in advance.

I am expecting the code to return blank cell in pandas dataframe when I run the code.



Solution 1:[1]

If need empty numeric value use missing value NaN:

np.where(df['Adj Close']> df['signal'], 1, np.nan)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jezrael