简体   繁体   中英

Reading in xls file into python

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')`

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')`

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM