[Python] In pandas, how to write the word "nan" as string with to_excel?

Discussão em 'Python' iniciado por Stack, Julho 29, 2025.

  1. Stack

    Stack Membro Participativo

    I have the reverse problem as described in this question: On Preventin pandas from interpreting 'NA' as NaN.

    I work with older English text data and want to write the word "nan" (i.e. Modern English 'non(e)') into an Excel file.

    On the one hand, I want Excel to show this word as "nan" for a particular column. On the other hand, I don't want empty cells elsewhere in my dataframe be filled with whatever other NaN-replacements you can think of in the Excel file.

    Instead, what I get when I use df.to_excel() is an empty cell.

    Many thanks in advance.

    Continue reading...

Compartilhe esta Página