I am working with a dataframe and am trying to find the counts of null values and the percentage of those counts for the column. Here is my code:
for x in df.columns[df.isnull().any()]:
print('____________________-')
print('Column Name:', x)
print('____________________-')
print(df[x].value_counts())
print(df[x].value_counts()*100/len(df))
What do I had to the code so that if the values are integers, both the counts and the percentages are sorted with 0.0 (the null values) first? Would it just be my code below the for loop with if/else statements? Is there a way to sort object data types so that null values are sorted to the top as well, or is that more difficult because of Boolean values?
if dtype==int:
some type of sorting code???
then my print statements?
Or would the print statements come after? Thanks in advance.
Just wanted to show what the output of this would be as an example:
______________________
'Some stuff here:', 1400.00
______________________
1385.00
98.9
This essentially a printout of null value percentages for each dimension in my data frame. I am using this information to determine whether to drop a column of keep it through my data cleaning process. Thanks.