Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (12.7k points)
Hello everyone. Assume I have a big spreadsheet file and I'm using the pandas package to process it. Like, I need data from two tabs in that big file. In those tabs, one tab will be having a ton of data and the other tab is just a few square cells.

If I use pd.read_excel(), it looks like the whole file is loaded. But, When I tried to use the method twice (once for each sheet), then I effectively need to suffer the whole workbook being read twice (even if we are using the specified sheet).

Anyone suggest to me, whether I'm using it wrong? If so, please help me

Thank you in advance :)

1 Answer

0 votes
by (26.4k points)

Try pd.ExcelFile:

xls = pd.ExcelFile('path_to_file.xls')

df1 = pd.read_excel(xls, 'Sheet1')

df2 = pd.read_excel(xls, 'Sheet2')

Note that the sheet_name contention to pd.read_excel() can be the name of the sheet (as over), a whole number determining the sheet number (eg 0, 1, and so on), a rundown of sheet names or records, or None. On the off chance that elite is given, it restores a word reference where the keys are the sheet names/files and the qualities are the information outlines. The default is to just restore the primary sheet (ie, sheet_name=0). 

In the event that None is determined, all sheets are returned, as a {sheet_name:dataframe} word reference.

To know more about Python, Come and Join: Python course

Browse Categories

...