Can one output something other than 'nan' for not a number values?

Chris Green cl at isbd.net
Mon Feb 19 07:08:00 EST 2024


Grant Edwards <grant.b.edwards at gmail.com> wrote:
> On 2024-02-16, Chris Green via Python-list <python-list at python.org> wrote:
> 
> > I'm looking for a simple way to make NaN values output as something
> > like '-' or even just a space instead of the string 'nan'.
> 
> It would probably help if you told us how you're "outputting" them now
> (the Python feaatures/functions used, not the actual output format).
> 
> Are you using f-strings, the % operator, str.format(), or ??
> 
> I would be tempted to try monkey-patching the float class to override
> the __format__ method. I have no idea what side effects that might
> have, or if it's even used by the various formatting mechanisms, so
> you might end up scraping bits off the walls...
> 
It's using f'{...}' at the moment.

-- 
Chris Green
·


More information about the Python-list mailing list