0

I am trying to read in an excel file with multiple sheets. But after reading in the sheets i can see python is rounding up values to 2 decimal places.some values vary in different length of decimal places. eg here just wondering how to stop this, I did think this might just have been i visual thing with python, but after writing the files to .xlsx it is the same there aswell. The dtype for the col is float64. Here is how im reading in the file

import pandas as pd

xls = pd.ExcelFile('Data.xls')
LPD = pd.read_excel(xls, 'Landing Page Data')
FI = pd.read_excel(xls, 'Fund Information')
MSCR = pd.read_excel(xls, 'MSC Rates')`
stfwn
  • 362
  • 2
  • 14
Pwa24777
  • 1
  • 1
  • See [this answer](https://stackoverflow.com/a/47368368/7613292) to what looks like a similar question. Does this fix your issue? – stfwn Nov 05 '20 at 13:19
  • @stfwn unfortunately not as 'The 'float_precision' option is not supported with the 'python' engine' but i did find the answer further down the page on that page – Pwa24777 Nov 05 '20 at 13:33
  • In that case it's encouraged to answer your own question in the box below so that others may find and use it in the future. – stfwn Nov 05 '20 at 13:36

2 Answers2

0

So to somewhat answer my question i needed to add a ,dtype='str' when reading in the file. But this has resulted in needing to make more changes to correct date columns etc.

If anyone has more ideas how to make this more simple, im all ears!

import pandas as pd

xls = pd.ExcelFile('Data.xls')
LPD = pd.read_excel(xls, 'Landing Page Data',dtype='str')
FI = pd.read_excel(xls, 'Fund Information',dtype='str')
MSCR = pd.read_excel(xls, 'MSC Rates',dtype='str')`
Pwa24777
  • 1
  • 1
0

Have You tried the float precision parameter when reading the csv ? Here You have documentation about this parameter https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#specifying-method-for-floating-point-conversion

Piotr Nowakowski
  • 376
  • 1
  • 11