1

Pandas and NumPy have a lot of ways to configure array and dataframe string conversion. These are mostly global options, set with numpy.set_printoptions and pandas.set_option.

NumPy also provides numpy.array2string to perform a single array stringification operation with detailed configuration for that specific operation. This avoids messing with global options that other parts of a program may be relying on.

The closest thing I've found in Pandas is pandas.option_context, which temporarily modifies global options and restores them afterward. (NumPy has the similar numpy.printoptions context manager.) However, this still modifies global options, making it unsuitable for concurrent code, or library code that might be used in a concurrent program.

Is there any call to stringify a dataframe with custom display options, without even temporarily modifying global settings?

0

1 Answer 1

3

pandas.DataFrame.to_string() has many of the options numpy.array2string() offers.

pandas.Series.to_string() is the analogous routine for Series objects.

Sign up to request clarification or add additional context in comments.

2 Comments

Just found the same method, after searching more. It wasn't linked from the set_option docs, so it was harder to find than array2string.
Looks like it doesn't support the same options as set_option, though - set_option has a ton of stringification-related options that DataFrame.to_string has no equivalent for. That's a bummer. numpy.array2string supports almost everything numpy.set_printoptions supports, except the nanstr and infstr options for some reason.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.