Home > OS >  Why the decimals places are truncated when creating a Series from an array?
Why the decimals places are truncated when creating a Series from an array?

Time:03-12

I have created a function that does many things. I need it to display two series that are created starting from a list. The problem is that while one of them is displayed correctly, the other one is like "truncated" in the decimals places. But the arrays on which these two series are based are identical. Only the numerical values in them changes.

beta_list = np.array(beta_list) # first array
delta_beta = np.array(pippo) #second array

magica1 = pd.Series(beta_list, index=indexer_array) # first series 
magica = pd.Series(delta_beta, index=indexer_array_delta) #second series

return magica, magica1, delta_beta, beta_list

When I call the function:

PROVA(XRP, BTC,0.25)


(125    9.827752e-06
 243    1.924225e-06
 273    1.616558e-07
 dtype: float64, 0     -0.000001
 125    0.000011
 176   -0.000011
 243    0.000013
 261   -0.000013
 273    0.000013
 dtype: float64, array([9.82775193e-06, 1.92422467e-06, 1.61655820e-07]), array([-1.15469635e-06,  1.09824483e-05, -1.10016071e-05,  1.29258318e-05,
        -1.30224291e-05,  1.31840849e-05]))

This is what i get. I can't understand why one array keep the same format and the other one doesn't

CodePudding user response:

The values greater than 1E-5 are displayed as float by default. Below this treshold the default format is scientific format. You can set the precision by calling the following instruction before printing the series :

pd.options.display.float_format = '{:12.5e}'.format
  • Related