Saturday, 8 January 2022

Pandas ExtensionDtype / ExtensionArray custom format for to_csv

In pandas extension interface (ExtensionDtype + ExtensionArray), is it possible to use a custom formatting when calling the to_csv function on a Series or a DataFrame which contains column of such a type?

It seems that the to_csv function will somehow call the __str__ function of the underlying scalar type object. However, I definitely want different formatting behavior between a call from str() and from to_csv.

In the ExtensionArray documentation we can find:

One can implement methods to handle parsing from strings that will be used in methods such as pandas.io.parsers.read_csv.

  - _from_sequence_of_strings

And I'm perfectly fine with it, but this is for reading from a string, not for writing it.



from Pandas ExtensionDtype / ExtensionArray custom format for to_csv

No comments:

Post a Comment