4

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 !

5 Answers 5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

replace sheetname with sheet_name in recent versions, as sheetname is now deprecated and replaced with the latter.
2
import pandas as pd

df = pd.read_excel('<your/path/here>.xlsx', sheet_name='<sheet/name/here>')

Specify at least your path, and your sheet_name. Do note that sheet_name is current in 2024, as sheetname has been deprecated.

Comments

0

Well, when I try:

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

I have something like that in df

https://i.sstatic.net/eb3iy.jpg

And I cannot put .fileformat in the sentence

Comments

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?

Comments

-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

2 Comments

I do not figure how to use it, I convert my excel file into a csv file but It does not work.
This surely doesn't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.