Skip to content
Advertisement

Tag: nan

How to plot percentage of NaN in pandas data frame?

I’d like someone to help me plot the NaN percentage of pandas data frame. I calculated percentage using this code. It gave me this result. Now, I want to plot the percentage along with the column names of data frame. Can anyone help me? Regards. Updated: The graph looks like this. How to beautify this in order to see the

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 initialize your weights with non zero values.

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 the “keyword”

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 database): I tried to separate

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 integer use convert_floating=False parameter. output Working with ints output

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

How to drop column according to NAN percentage for dataframe?

For certain columns of df, if 80% of the column is NAN. What’s the simplest code to drop such columns? Answer You can use isnull with mean for threshold and then remove columns by boolean indexing with loc (because remove columns), also need invert condition – so <.8 means remove all columns >=0.8: Sample: If want remove columns by minimal

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 introduced. Answer

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 section “Working with missing data” in the Pandas

Advertisement