When you print a Series with with dtype object or string, the elements are printed as if you called str().
For example, print(pd.Series(['a', 'b', 'c'])) yields:
0 a
1 b
2 c
dtype: object
Is it possible to tell Pandas to use repr() and not str() to render elements for printing? The desired output in the example above would be:
0 'a'
1 'b'
2 'c'
dtype: object
As a workaround, you can call my_series.apply(repr), but it would be nice if I could set this as some kind of Pandas option more generally. I looked in the list of Pandas options in the docs and didn't see anything like this.
This does not currently seem possible in Pandas. I have made a feature request here: https://github.com/pandas-dev/pandas/issues/46744 but this might be considered too niche to be worth adding to Pandas.
The best workaround is to use DataFrame.to_string, with repr as the formatter for every string/object column.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With