Skip to content
Advertisement

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.

JavaScript

It gave me this result.

JavaScript

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 column name clearly?

Graph

Also, is it possible to show the percentage on each bar like shown in this below graph?

percentage


Update: The only issue is with HR percentage:

pic

Advertisement

Answer

You can plot a barplot using the following code snippet::

JavaScript

Sample output:

enter image description here

UPDATE:

As per your update to the question, here is a solution that retains only columns having percentage greater than zero. Also the plot has been beautified as requested with values displayed over each bar.

JavaScript

Sample Output:

enter image description here

UPDATE 2:

To round the decimals to two decimal places, replace this line in the earlier code:

ax.text(i - 0.25, item[1] + 1.5 , str(np.round(item[1],2)))

You will need to import numpy if not already done: import numpy as np

Advertisement