Hi, 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.
If you are using Python, I think it make sense to think pythonically, instead of treating python as spreadsheet. What exactly you mean by empty? The returned array has a defined size, and each element must contains something. What this "something" is depends on your purpose. If you mean an empty string, "" or '' should work. If you mean generic missing value, try np.nan. Note: the returned array from np.where will have a single data type for all elements of the array. So if you are using string values like '' or "" then, the 1 will be a cast as string as well (i.e. "1"). If you use np.nan, the array will be float (so 1 will be 1.0 or equivalent floating point representation of 1). If you need the array to remain an integer array, you need to define a sentinel value, for e.g. a large integer which flag an integer missing value in your code.