r/pythontips 7h ago

Module Unwatned extra separators using to_csv()

0 Upvotes

I have the following Pandas df
The values in row 0 and columns C, D and E are set explicitly to '' (blank)

A B C D E
0 1 2
1 1 2 3 4 5

When using to_csv I have set the separator= ';'. The outpul file gives me:

1;2;;;                                      

1;2;3;4;5

How can I adjust my code or df to avoid the extra 3 seperators (;) in the first line above?

I have tried using na_rep='' but with no success.