Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change How Pandas Displays nan

If I remember correctly, in Stata nan are displayed as .. Displaying them as such is particularly helpful if you have a lot of missing values as it draws emphasis to the filled values rather than the reverse. Is there any option in Pandas for an alternative nan display?

x = (pd.DataFrame(np.random.rand(10,5)) * 100).round()
x[x>10] = np.nan
x
    0       1       2       3       4
0   NaN     NaN     NaN     NaN     NaN
1   NaN     NaN     NaN     1.0     5.0
2   NaN     NaN     NaN     0.0     NaN
3   1.0     NaN     NaN     NaN     9.0
4   NaN     NaN     NaN     NaN     NaN

# Preferably a parameter that set this functionality:
x.fillna('.')
    0   1   2   3   4
0   .   .   .   .   .
1   .   .   .   1   5
2   .   .   .   0   .
3   1   .   .   .   9
4   .   .   .   .   .
like image 961
Francis Smart Avatar asked Dec 10 '20 23:12

Francis Smart


1 Answers

You can use Pandas styling, as shown here

df.style.set_na_rep(".")
like image 148
ev350 Avatar answered Sep 21 '22 12:09

ev350