Pandas read_excel: only read first few lines
See original GitHub issueCode Sample, a copy-pastable example if possible
workbook_dataframe = pd.read_excel(workbook_filename, nrows = 10)
Problem description
Using pandas read_excel on about 100 excel files - some are large - I want to read the first few lines of each (header and first few rows of data).
The above doesn’t work but illustrates the goal (example reading 10 data rows).
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Pandas read_excel: only read first few lines - Stack Overflow
Problem with the workaround is it has to read the entire excel file before taking the head. I've also tried experimenting with skiprows...
Read more >pandas.read_excel — pandas 1.5.2 documentation
Read an Excel file into a pandas DataFrame. Supports xls , xlsx , xlsm , xlsb , odf , ods and odt file...
Read more >Pandas - read_excel() - How to read Excel file in python
Let's say we want to skip the first 2 rows when reading the file. df = pd.read_excel('reading_excel_file.xlsx', sheet_name='Purchase Orders 1', ...
Read more >Pandas Read Excel with Examples
Use pandas.read_excel() function to read excel sheet into pandas DataFrame, by default it loads the first sheet from the excel file and parses...
Read more >Pandas read_excel() - Reading Excel File in Python
We can specify the column names to be read from the excel file. It's useful when you are interested in only a few...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
To get nrows without reading the entire worksheet:
You can add one line in your code below where you are reading your file. For example, if you want to read first 10 rows of the file then you can do this.
workbook_dataframe = pd.read_excel(workbook_filename) workbook_dataframe =workbook_dataframe.iloc[:10]
or even you can simply do this workbook_dataframe = pd.read_excel(workbook_filename).iloc[:10]
so that your data frame now contains only first 10 rows.