3

I want to put some data available in an excel file into a dataframe in Python. The code I use is as below (two examples I use to read an excel file):

d=pd.ExcelFile(fileName).parse('CT_lot4_LDO_3Tbin1')
e=pandas.read_excel(fileName, sheetname='CT_lot4_LDO_3Tbin1',convert_float=True)

The problem is that the dataframe I get has the values with only two numbers after comma. In other words, excel values are like 0.123456 and I get into the dataframe values like 0.12.

A round up or something like that seems to be done, but I cannot find how to change it.

Can anyone help me?

thanks for the help !

James
  • 32,991
  • 4
  • 47
  • 70
Guillaume
  • 31
  • 1
  • 1
  • 2

4 Answers4

2

You can try this. I used test.xlsx which has two sheets, and 'CT_lot4_LDO_3Tbin1' is the second sheet. I also set the first value as Text format in excel.

import pandas as pd 
fileName = 'test.xlsx'
df = pd.read_excel(fileName,sheetname='CT_lot4_LDO_3Tbin1')

Result:

In [9]: df
Out[9]: 
       Test
0  0.123456
1  0.123456
2  0.132320

Without seeing the real raw data file, I think this is the best answer I can think of.

0

Well, when I try:

df = pd.read_csv(r'my file name')

I have something like that in df

https://i.stack.imgur.com/eb3iy.jpg

And I cannot put .fileformat in the sentence

Guillaume
  • 31
  • 1
  • 1
  • 2
0

You might be interested in removing column datatype inference that pandas performs automatically. This is done by manually specifying the datatype for the column. Here is what you might be looking for.

Python pandas: how to specify data types when reading an Excel file?

synaptikon
  • 699
  • 1
  • 8
  • 16
-1

Using pandas 0.20.1 something like this should work:

df = pd.read_csv('CT_lot4_LDO_3Tbin1.fileformat')

for exemple, in excel:

df = pd.read_csv('CT_lot4_LDO_3Tbin1.xlsx')

Read this documentation: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html

Leonardo Ferreira
  • 385
  • 1
  • 3
  • 11