Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas changes default numpy array format

Is there any way to prevent pandas from changing the default print format for numpy arrays?

With plain numpy, I get:

>>> numpy.array([123.45, 0.06])
array([  1.23450000e+02,   6.00000000e-02])

After I import pandas, I get:

>>> numpy.array([123.45, 0.06])
array([ 123.45,    0.06])

Can I stop it from doing this as a configuration setting? I don't want to have to wrap every "import pandas" with a "foo=np.get_printoptions(); import pandas; np.set_printoptions(**foo)", but that's the best I can come up with.

As it is, if I import pandas in one place, I get doctest errors from another.

like image 652
Johann Hibschman Avatar asked May 09 '26 03:05

Johann Hibschman


1 Answers

You should only have to wrap the first import pandas with np.set_printoptions(foo) since python will cache it. See below:

import numpy
>>> numpy.array([123.45, 0.06])
array([  1.23450000e+02,   6.00000000e-02])
>>> import pandas
>>> numpy.array([123.45, 0.06])
array([ 123.45,    0.06])
>>> numpy.set_printoptions(edgeitems=3,infstr='inf', linewidth=75, nanstr='nan', precision=8, suppress=False, threshold=1000)
>>> numpy.array([123.45, 0.06])
array([  1.23450000e+02,   6.00000000e-02])
>>> import pandas
>>> numpy.array([123.45, 0.06])
array([  1.23450000e+02,   6.00000000e-02])
like image 167
sbraden Avatar answered May 12 '26 12:05

sbraden