Guillaume
Guillaume

Reputation: 41

Python: convert excel data into dataframes

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 !

Upvotes: 4

Views: 37892

Answers (5)

Nebulous
Nebulous

Reputation: 68

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.

Upvotes: 1

synaptikon
synaptikon

Reputation: 699

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?

Upvotes: 0

Chih-Hsu Jack Lin
Chih-Hsu Jack Lin

Reputation: 453

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.

Upvotes: 2

Guillaume
Guillaume

Reputation: 41

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

Upvotes: 0

Leonardo Ferreira
Leonardo Ferreira

Reputation: 384

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

Upvotes: -1

Related Questions