I have NAN values in my dataframe columns and i need to replace it with empty string. I need to perform subtraction on these columns, so when replacing with empty string i am getting error:
unsupported operand types for -:'str' and 'str'.
so while applying style to my dataframe i have added this line, and it is working as well:
df.style.set_na_rep('')
But when i am adding format function to the style, to concat '%' symbol in the columns, the NAN values are reappearing along withe the '%' symbol.
Then syntax is:
df = (df.style.apply(highlight_cells, axis = None).set_na_rep('')).format({'B':'{:}%','C':'{:}%'}).set_table_styles(...)
A | B | C |
---|---|---|
ab | 8.3% | 4.7% |
cd | 9.0% | NAN% |
ef | NAN% | NAN% |
gh | NAN% | 13.9% |
can anyone please suggest, I am pretty new in pandas and dataframes. Thanks