Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

I am trying to read an excel file this way :

newFile = pd.ExcelFile(PATH\FileName.xlsx)

ParsedData = pd.io.parsers.ExcelFile.parse(newFile)

which throws an error that says two arguments expected, I don't know what the second argument is and also what I am trying to achieve here is to convert an Excel file to a DataFrame, Am I doing it the right way? or is there any other way to do this using pandas?

1 Answer

0 votes
by (41.4k points)
edited by

1.Call ExcelFile

2.Then you call the .parse method and pass it the sheet name.

>>> xl = pd.ExcelFile("dummydata.xlsx")

>>> xl.sheet_names

[u'Sheet1', u'Sheet2', u'Sheet3']

>>> df = xl.parse("Sheet1")

>>> df.head()

                  Tid  dummy1    dummy2    dummy3    dummy4    dummy5  \

0 2006-09-01 00:00:00       0  5.894611  0.605211  3.842871  8.265307   

1 2006-09-01 01:00:00       0  5.712107  0.605211  3.416617  8.301360   

2 2006-09-01 02:00:00       0  5.105300  0.605211  3.090865  8.335395   

3 2006-09-01 03:00:00       0  4.098209  0.605211  3.198452  8.170187   

4 2006-09-01 04:00:00       0  3.338196  0.605211  2.970015  7.765058   

     dummy6  dummy7    dummy8    dummy9  

0  0.623354       0  2.579108  2.681728  

1  0.554211       0  7.210000  3.028614  

2  0.567841       0  6.940000  3.644147  

3  0.581470       0  6.630000  4.016155  

4  0.595100       0  6.350000  3.974442  

If you are interested in learning Pandas and want to become an expert in Python Programming, then check out this Python Course and upskill yourself.

To know more about this you can have a look at the following video tutorial:- 

Browse Categories

...