Skip to content

Tag: nan

Python function returns nan

I have written function for gradient descent and used pandas to read csv file. But when I use data read by pandas, the function returns “nan”. I can’t understand why. Thanks in advance. Answer It might be a vanishing gradient problem. You gradients might be very close or even zero. Try to in…

Trouble when adding values for NaN in DataFrame

I have this DataFrame: And I want to fill the NaN values with keyword taken from the description. To that end I created a list with the keywords I want: Finally, I want to loop over each row in the DataFrame. Split the contents from the “description” column in each row and, if that word is also in…

Change a column format while ignoring (or keeping) NaN

I want to change a column from a DataFrame which contains values of this format hh:mm:ss to a column containing the number of minutes (while keeping the NaN values) I can’t change it directly from the excel file so I’ve tried to do it with pandas (I’m working on a ML model with a health data…

Convert np.nan to pd.NA

How can I convert np.nan into the new pd.NA format, given the pd.DataFrame comprises float? Making use of pd.convert_dtypes() doesn’t seem to work when df comprises float. This conversion is however working fine when df contains int. Answer From v1.2 this now works with floats by default and if you want…

How to drop dictionaries with NaN values from list

This seems like a fairly simple thing but I haven’t been able to find an answer for it here (yet). I have a list of dictionaries, and some of the dictionaries in the list have NaN values. I just need to drop any dictionary from the list if it has a NaN value in it. I’ve tried it a few

pandas concat generates nan values

I am curious why a simple concatenation of two dataframes in pandas: of the same shape and both without NaN values can result in a lot of NaN values if joined. How can I fix this problem and prevent NaN values being introduced? Trying to reproduce it like failed e.g. worked just fine as no NaN values were int…

How do you represent missing data in a Pandas DataFrame?

Does Pandas have an equivalent of R’s na (meaning not available)? If not, what is the convention for representing a missing value, as opposed to NaN which represents a mathematically impossible value such as a divide by zero? Answer Currently there is no NA value available in Pandas or NumPy. From the s…