[{"data":1,"prerenderedAt":2000},["ShallowReactive",2],{"doc:\u002Fgetting-started-with-python-excel-automation\u002Freading-excel-files-with-pandas\u002Fread-only-some-rows-of-an-excel-file-with-pandas":3,"surround:\u002Fgetting-started-with-python-excel-automation\u002Freading-excel-files-with-pandas\u002Fread-only-some-rows-of-an-excel-file-with-pandas":1966,"ancestors:\u002Fgetting-started-with-python-excel-automation\u002Freading-excel-files-with-pandas\u002Fread-only-some-rows-of-an-excel-file-with-pandas":1974,"children:\u002Fgetting-started-with-python-excel-automation\u002Freading-excel-files-with-pandas\u002Fread-only-some-rows-of-an-excel-file-with-pandas":1979,"related:\u002Fgetting-started-with-python-excel-automation\u002Freading-excel-files-with-pandas\u002Fread-only-some-rows-of-an-excel-file-with-pandas":1980},{"id":4,"title":5,"body":6,"dateModified":1929,"datePublished":1929,"description":1930,"extension":1931,"faq":1932,"keyword":1943,"kind":1944,"meta":1945,"navigation":438,"path":1955,"seo":1956,"slug":1959,"stem":1960,"topics":1961,"type":1964,"__hash__":1965},"docs\u002Fgetting-started-with-python-excel-automation\u002Freading-excel-files-with-pandas\u002Fread-only-some-rows-of-an-excel-file-with-pandas\u002Findex.md","Read Only Some Rows of an Excel File with pandas",{"type":7,"value":8,"toc":1916},"minimark",[9,36,359,364,394,397,582,586,600,652,667,671,685,795,806,954,958,967,1060,1063,1162,1165,1169,1175,1299,1306,1438,1453,1457,1467,1559,1562,1738,1751,1755,1810,1814,1825,1829,1843,1847,1853,1859,1869,1875,1881,1885,1912],[10,11,12,13,17,18,21,22,25,26,29,30,35],"p",{},"Sometimes you do not want the whole sheet. You want a preview of the first twenty rows to check the layout, the current week out of a year of history, a sample to test a pipeline against, or just the last batch appended to a log workbook. ",[14,15,16],"code",{},"pandas.read_excel"," has three parameters for this — ",[14,19,20],{},"nrows",", ",[14,23,24],{},"skiprows"," and ",[14,27,28],{},"skipfooter"," — and they combine to cut almost any horizontal slice out of a sheet. This guide, part of ",[31,32,34],"a",{"href":33},"\u002Fgetting-started-with-python-excel-automation\u002Freading-excel-files-with-pandas\u002F","Reading Excel Files with pandas",", shows each slice, the counting rules that trip people up, and which options genuinely make a big file faster to read rather than just smaller once read.",[37,38,46,47,46,51,46,55,46,63,46,73,46,78,46,89,46,96,46,102,46,105,46,111,46,115,46,119,46,123,46,127,46,131,46,136,46,140,46,144,46,146,46,149,46,151,46,154,46,157,46,161,46,165,46,169,46,171,46,174,46,176,46,179,46,182,46,186,46,188,46,191,46,193,46,196,46,198,46,201,46,204,46,208,46,212,46,216,46,218,46,221,46,223,46,226,46,229,46,233,46,235,46,238,46,240,46,243,46,245,46,248,46,251,46,255,46,257,46,260,46,262,46,264,46,266,46,269,46,272,46,276,46,278,46,282,46,284,46,286,46,288,46,291,46,294,46,297,46,299,46,302,46,304,46,306,46,308,46,311,46,318,46,323,46,330,46,336,46,340,46,345,46,349,46,353],"svg",{"viewBox":39,"role":40,"ariaLabelledBy":41,"xmlns":44,"style":45},"68 0 623 336","img",[42,43],"rows-window-t","rows-window-d","http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg","width:100%;max-width:623px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif","\n  ",[48,49,50],"title",{"id":42},"The three row parameters of read_excel on one sheet",[52,53,54],"desc",{"id":43},"A worksheet with a header on row 1. skiprows removes rows 2 and 3, nrows then keeps the next three rows, and everything below is never loaded. skipfooter would instead trim rows from the bottom.",[56,57],"rect",{"x":58,"y":59,"width":60,"height":61,"fill":62},"68","0","623","336","#ffffff",[56,64],{"x":65,"y":66,"width":67,"height":68,"rx":69,"fill":70,"stroke":71,"style":72},"114.4","16.0","241.2","30.0","8","#e7ebef","var(--line,#cdd5e6)","stroke-width:1.5px",[56,74],{"x":65,"y":75,"width":67,"height":76,"rx":59,"fill":70,"stroke":71,"style":77},"38.0","8.0","stroke-width:0px",[79,80,82],"g",{"transform":81},"translate(124.4,23.0) scale(0.667)",[83,84],"path",{"d":85,"fill":86,"stroke":87,"style":88},"M6 3h9l4 4v14H6z M15 3v4h4 M9.5 11.5l4.5 6 M14 11.5l-4.5 6","none","var(--teal-ink,#0b6157)","stroke-width:2.70px;stroke-linecap:round;stroke-linejoin:round",[90,91,95],"text",{"x":92,"y":93,"style":94},"146.4","36.0","font-size:12px;font-weight:700;fill:var(--text,#172033);text-anchor:start","orders.xlsx",[56,97],{"x":65,"y":98,"width":99,"height":100,"rx":59,"fill":70,"stroke":71,"style":101},"46.0","32.0","24.0","stroke-width:1px",[56,103],{"x":92,"y":98,"width":104,"height":100,"rx":59,"fill":70,"stroke":71,"style":101},"74.8",[90,106,110],{"x":107,"y":108,"style":109},"183.8","63.0","font-size:11px;font-weight:600;fill:var(--muted,#5b6780);text-anchor:middle","A",[56,112],{"x":113,"y":98,"width":114,"height":100,"rx":59,"fill":70,"stroke":71,"style":101},"221.2","63.6",[90,116,118],{"x":117,"y":108,"style":109},"253.0","B",[56,120],{"x":121,"y":98,"width":122,"height":100,"rx":59,"fill":70,"stroke":71,"style":101},"284.8","70.9",[90,124,126],{"x":125,"y":108,"style":109},"320.2","C",[56,128],{"x":65,"y":129,"width":99,"height":130,"rx":59,"fill":70,"stroke":71,"style":101},"70.0","28.0",[90,132,135],{"x":133,"y":134,"style":109},"130.4","89.0","1",[56,137],{"x":92,"y":129,"width":104,"height":130,"rx":59,"fill":138,"stroke":139,"style":72},"#f0f4ff","var(--brand,#5b5cf0)",[90,141,143],{"x":107,"y":134,"style":142},"font-size:12px;font-weight:700;fill:var(--brand-strong,#4338ca);text-anchor:middle","order_id",[56,145],{"x":113,"y":129,"width":114,"height":130,"rx":59,"fill":138,"stroke":139,"style":72},[90,147,148],{"x":117,"y":134,"style":142},"region",[56,150],{"x":121,"y":129,"width":122,"height":130,"rx":59,"fill":138,"stroke":139,"style":72},[90,152,153],{"x":125,"y":134,"style":142},"amount",[56,155],{"x":65,"y":156,"width":99,"height":130,"rx":59,"fill":70,"stroke":71,"style":101},"98.0",[90,158,160],{"x":133,"y":159,"style":109},"117.0","2",[56,162],{"x":92,"y":156,"width":104,"height":130,"rx":59,"fill":163,"stroke":164,"style":72},"#fee8f2","var(--accent,#f43f8f)",[90,166,168],{"x":107,"y":159,"style":167},"font-size:12px;font-weight:700;fill:var(--accent-ink,#be185d);text-anchor:middle","1001",[56,170],{"x":113,"y":156,"width":114,"height":130,"rx":59,"fill":163,"stroke":164,"style":72},[90,172,173],{"x":117,"y":159,"style":167},"North",[56,175],{"x":121,"y":156,"width":122,"height":130,"rx":59,"fill":163,"stroke":164,"style":72},[90,177,178],{"x":125,"y":159,"style":167},"120.50",[56,180],{"x":65,"y":181,"width":99,"height":130,"rx":59,"fill":70,"stroke":71,"style":101},"126.0",[90,183,185],{"x":133,"y":184,"style":109},"145.0","3",[56,187],{"x":92,"y":181,"width":104,"height":130,"rx":59,"fill":163,"stroke":164,"style":72},[90,189,190],{"x":107,"y":184,"style":167},"1002",[56,192],{"x":113,"y":181,"width":114,"height":130,"rx":59,"fill":163,"stroke":164,"style":72},[90,194,195],{"x":117,"y":184,"style":167},"South",[56,197],{"x":121,"y":181,"width":122,"height":130,"rx":59,"fill":163,"stroke":164,"style":72},[90,199,200],{"x":125,"y":184,"style":167},"98.00",[56,202],{"x":65,"y":203,"width":99,"height":130,"rx":59,"fill":70,"stroke":71,"style":101},"154.0",[90,205,207],{"x":133,"y":206,"style":109},"173.0","4",[56,209],{"x":92,"y":203,"width":104,"height":130,"rx":59,"fill":210,"stroke":211,"style":72},"#d9f4f1","var(--teal,#0f9488)",[90,213,215],{"x":107,"y":206,"style":214},"font-size:12px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:middle","1003",[56,217],{"x":113,"y":203,"width":114,"height":130,"rx":59,"fill":210,"stroke":211,"style":72},[90,219,220],{"x":117,"y":206,"style":214},"East",[56,222],{"x":121,"y":203,"width":122,"height":130,"rx":59,"fill":210,"stroke":211,"style":72},[90,224,225],{"x":125,"y":206,"style":214},"143.90",[56,227],{"x":65,"y":228,"width":99,"height":130,"rx":59,"fill":70,"stroke":71,"style":101},"182.0",[90,230,232],{"x":133,"y":231,"style":109},"201.0","5",[56,234],{"x":92,"y":228,"width":104,"height":130,"rx":59,"fill":210,"stroke":211,"style":72},[90,236,237],{"x":107,"y":231,"style":214},"1004",[56,239],{"x":113,"y":228,"width":114,"height":130,"rx":59,"fill":210,"stroke":211,"style":72},[90,241,242],{"x":117,"y":231,"style":214},"West",[56,244],{"x":121,"y":228,"width":122,"height":130,"rx":59,"fill":210,"stroke":211,"style":72},[90,246,247],{"x":125,"y":231,"style":214},"87.15",[56,249],{"x":65,"y":250,"width":99,"height":130,"rx":59,"fill":70,"stroke":71,"style":101},"210.0",[90,252,254],{"x":133,"y":253,"style":109},"229.0","6",[56,256],{"x":92,"y":250,"width":104,"height":130,"rx":59,"fill":210,"stroke":211,"style":72},[90,258,259],{"x":107,"y":253,"style":214},"1005",[56,261],{"x":113,"y":250,"width":114,"height":130,"rx":59,"fill":210,"stroke":211,"style":72},[90,263,173],{"x":117,"y":253,"style":214},[56,265],{"x":121,"y":250,"width":122,"height":130,"rx":59,"fill":210,"stroke":211,"style":72},[90,267,268],{"x":125,"y":253,"style":214},"310.00",[56,270],{"x":65,"y":271,"width":99,"height":130,"rx":59,"fill":70,"stroke":71,"style":101},"238.0",[90,273,275],{"x":133,"y":274,"style":109},"257.0","7",[56,277],{"x":92,"y":271,"width":104,"height":130,"rx":59,"fill":62,"stroke":71,"style":101},[90,279,281],{"x":107,"y":274,"style":280},"font-size:12px;font-weight:400;fill:var(--text,#172033);text-anchor:middle","1006",[56,283],{"x":113,"y":271,"width":114,"height":130,"rx":59,"fill":62,"stroke":71,"style":101},[90,285,195],{"x":117,"y":274,"style":280},[56,287],{"x":121,"y":271,"width":122,"height":130,"rx":59,"fill":62,"stroke":71,"style":101},[90,289,290],{"x":125,"y":274,"style":280},"42.75",[56,292],{"x":65,"y":293,"width":99,"height":130,"rx":59,"fill":70,"stroke":71,"style":101},"266.0",[90,295,69],{"x":133,"y":296,"style":109},"285.0",[56,298],{"x":92,"y":293,"width":104,"height":130,"rx":59,"fill":62,"stroke":71,"style":101},[90,300,301],{"x":107,"y":296,"style":280},"1007",[56,303],{"x":113,"y":293,"width":114,"height":130,"rx":59,"fill":62,"stroke":71,"style":101},[90,305,220],{"x":117,"y":296,"style":280},[56,307],{"x":121,"y":293,"width":122,"height":130,"rx":59,"fill":62,"stroke":71,"style":101},[90,309,310],{"x":125,"y":296,"style":280},"66.10",[312,313],"line",{"x1":314,"y1":315,"x2":316,"y2":315,"stroke":139,"style":317},"363.6","155.0","395.6","stroke-width:2px",[319,320],"polygon",{"points":321,"fill":322},"399.6,155.0 390.6,160.0 390.6,150.0","#5b5cf0",[56,324],{"x":325,"y":326,"width":327,"height":328,"rx":329,"fill":210,"stroke":211,"style":317},"405.6","99.2","240.0","111.5","12",[90,331,335],{"x":332,"y":333,"style":334},"525.6","124.8","font-size:13.5px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:middle","header=0, skiprows=[1, 2],",[90,337,339],{"x":332,"y":338,"style":334},"142.2","nrows=3",[90,341,344],{"x":332,"y":342,"style":343},"161.8","font-size:11.5px;font-weight:400;fill:var(--text,#172033);text-anchor:middle","pink rows skipped",[90,346,348],{"x":332,"y":347,"style":343},"179.2","teal rows returned",[90,350,352],{"x":332,"y":351,"style":343},"196.8","rows below not read",[90,354,358],{"x":355,"y":356,"style":357},"380.0","316.0","font-size:12.5px;font-weight:400;fill:var(--muted,#5b6780);text-anchor:middle","skiprows counts file rows from zero, header included; nrows counts data rows after the header",[360,361,363],"h2",{"id":362},"prerequisites","Prerequisites",[365,366,371],"pre",{"className":367,"code":368,"language":369,"meta":370,"style":370},"language-bash shiki shiki-themes github-light github-dark-high-contrast","pip install pandas openpyxl python-calamine\n","bash","",[14,372,373],{"__ignoreMap":370},[374,375,377,381,385,388,391],"span",{"class":312,"line":376},1,[374,378,380],{"class":379},"sMTad","pip",[374,382,384],{"class":383},"srMev"," install",[374,386,387],{"class":383}," pandas",[374,389,390],{"class":383}," openpyxl",[374,392,393],{"class":383}," python-calamine\n",[10,395,396],{},"The examples build their own workbook so every block runs as written. It has 60,000 orders — big enough for the timing differences to show:",[365,398,402],{"className":399,"code":400,"language":401,"meta":370,"style":370},"language-python shiki shiki-themes github-light github-dark-high-contrast","import numpy as np\nimport pandas as pd\n\nrng = np.random.default_rng(7)\nn = 60_000\norders = pd.DataFrame({\n    \"order_id\": np.arange(1, n + 1),\n    \"region\": rng.choice([\"North\", \"South\", \"East\", \"West\"], n),\n    \"amount\": np.round(rng.random(n) * 1000, 2),\n})\norders.to_excel(\"orders.xlsx\", index=False)\n","python",[14,403,404,420,433,440,458,469,480,503,533,554,560],{"__ignoreMap":370},[374,405,406,410,414,417],{"class":312,"line":376},[374,407,409],{"class":408},"s-kum","import",[374,411,413],{"class":412},"skGVy"," numpy ",[374,415,416],{"class":408},"as",[374,418,419],{"class":412}," np\n",[374,421,423,425,428,430],{"class":312,"line":422},2,[374,424,409],{"class":408},[374,426,427],{"class":412}," pandas ",[374,429,416],{"class":408},[374,431,432],{"class":412}," pd\n",[374,434,436],{"class":312,"line":435},3,[374,437,439],{"emptyLinePlaceholder":438},true,"\n",[374,441,443,446,449,452,455],{"class":312,"line":442},4,[374,444,445],{"class":412},"rng ",[374,447,448],{"class":408},"=",[374,450,451],{"class":412}," np.random.default_rng(",[374,453,275],{"class":454},"sP0c6",[374,456,457],{"class":412},")\n",[374,459,461,464,466],{"class":312,"line":460},5,[374,462,463],{"class":412},"n ",[374,465,448],{"class":408},[374,467,468],{"class":454}," 60_000\n",[374,470,472,475,477],{"class":312,"line":471},6,[374,473,474],{"class":412},"orders ",[374,476,448],{"class":408},[374,478,479],{"class":412}," pd.DataFrame({\n",[374,481,483,486,489,491,494,497,500],{"class":312,"line":482},7,[374,484,485],{"class":383},"    \"order_id\"",[374,487,488],{"class":412},": np.arange(",[374,490,135],{"class":454},[374,492,493],{"class":412},", n ",[374,495,496],{"class":408},"+",[374,498,499],{"class":454}," 1",[374,501,502],{"class":412},"),\n",[374,504,506,509,512,515,517,520,522,525,527,530],{"class":312,"line":505},8,[374,507,508],{"class":383},"    \"region\"",[374,510,511],{"class":412},": rng.choice([",[374,513,514],{"class":383},"\"North\"",[374,516,21],{"class":412},[374,518,519],{"class":383},"\"South\"",[374,521,21],{"class":412},[374,523,524],{"class":383},"\"East\"",[374,526,21],{"class":412},[374,528,529],{"class":383},"\"West\"",[374,531,532],{"class":412},"], n),\n",[374,534,536,539,542,545,548,550,552],{"class":312,"line":535},9,[374,537,538],{"class":383},"    \"amount\"",[374,540,541],{"class":412},": np.round(rng.random(n) ",[374,543,544],{"class":408},"*",[374,546,547],{"class":454}," 1000",[374,549,21],{"class":412},[374,551,160],{"class":454},[374,553,502],{"class":412},[374,555,557],{"class":312,"line":556},10,[374,558,559],{"class":412},"})\n",[374,561,563,566,569,571,575,577,580],{"class":312,"line":562},11,[374,564,565],{"class":412},"orders.to_excel(",[374,567,568],{"class":383},"\"orders.xlsx\"",[374,570,21],{"class":412},[374,572,574],{"class":573},"sa561","index",[374,576,448],{"class":408},[374,578,579],{"class":454},"False",[374,581,457],{"class":412},[360,583,585],{"id":584},"step-1-the-first-rows-nrows","Step 1 — The first rows: nrows",[10,587,588,590,591,595,596,599],{},[14,589,20],{}," is the one you will use most. It limits the number of ",[592,593,594],"em",{},"data"," rows returned; the header is read in addition, so ",[14,597,598],{},"nrows=5"," gives five rows and correct column names.",[365,601,603],{"className":399,"code":602,"language":401,"meta":370,"style":370},"head = pd.read_excel(\"orders.xlsx\", nrows=5)\nprint(head)\nprint(len(head))  # 5\n",[14,604,605,627,635],{"__ignoreMap":370},[374,606,607,610,612,615,617,619,621,623,625],{"class":312,"line":376},[374,608,609],{"class":412},"head ",[374,611,448],{"class":408},[374,613,614],{"class":412}," pd.read_excel(",[374,616,568],{"class":383},[374,618,21],{"class":412},[374,620,20],{"class":573},[374,622,448],{"class":408},[374,624,232],{"class":454},[374,626,457],{"class":412},[374,628,629,632],{"class":312,"line":422},[374,630,631],{"class":454},"print",[374,633,634],{"class":412},"(head)\n",[374,636,637,639,642,645,648],{"class":312,"line":435},[374,638,631],{"class":454},[374,640,641],{"class":412},"(",[374,643,644],{"class":454},"len",[374,646,647],{"class":412},"(head))  ",[374,649,651],{"class":650},"s-wDw","# 5\n",[10,653,654,655,657,658,661,662,666],{},"That is the right way to preview an unfamiliar workbook: confirm the header landed where you expected, check the dtypes pandas inferred, and only then read the whole thing. A preview also tells you quickly when the real header is not on the first row — in which case combine ",[14,656,20],{}," with ",[14,659,660],{},"header=",", covered in ",[31,663,665],{"href":664},"\u002Fgetting-started-with-python-excel-automation\u002Freading-excel-files-with-pandas\u002Fskip-rows-and-set-header-when-reading-excel-with-pandas\u002F","Skip Rows and Set the Header When Reading Excel with pandas",".",[360,668,670],{"id":669},"step-2-a-window-in-the-middle-skiprows-plus-nrows","Step 2 — A window in the middle: skiprows plus nrows",[10,672,673,674,676,677,679,680,684],{},"To read rows 1,001 to 1,500, skip everything between the header and your window, then take the window with ",[14,675,20],{},". ",[14,678,24],{}," accepts a list or range of ",[681,682,683],"strong",{},"zero-based file positions",", and position 0 is the header — which is why the range below starts at 1: the header stays, the data rows before the window go.",[365,686,688],{"className":399,"code":687,"language":401,"meta":370,"style":370},"start, size = 1_000, 500               # data rows 1,001 to 1,500\nwindow = pd.read_excel(\n    \"orders.xlsx\",\n    skiprows=range(1, start + 1),      # keep file row 0, the header\n    nrows=size,\n)\nprint(window[\"order_id\"].iloc[[0, -1]].tolist())  # [1001, 1500]\n",[14,689,690,708,718,726,753,763,767],{"__ignoreMap":370},[374,691,692,695,697,700,702,705],{"class":312,"line":376},[374,693,694],{"class":412},"start, size ",[374,696,448],{"class":408},[374,698,699],{"class":454}," 1_000",[374,701,21],{"class":412},[374,703,704],{"class":454},"500",[374,706,707],{"class":650},"               # data rows 1,001 to 1,500\n",[374,709,710,713,715],{"class":312,"line":422},[374,711,712],{"class":412},"window ",[374,714,448],{"class":408},[374,716,717],{"class":412}," pd.read_excel(\n",[374,719,720,723],{"class":312,"line":435},[374,721,722],{"class":383},"    \"orders.xlsx\"",[374,724,725],{"class":412},",\n",[374,727,728,731,733,736,738,740,743,745,747,750],{"class":312,"line":442},[374,729,730],{"class":573},"    skiprows",[374,732,448],{"class":408},[374,734,735],{"class":454},"range",[374,737,641],{"class":412},[374,739,135],{"class":454},[374,741,742],{"class":412},", start ",[374,744,496],{"class":408},[374,746,499],{"class":454},[374,748,749],{"class":412},"),      ",[374,751,752],{"class":650},"# keep file row 0, the header\n",[374,754,755,758,760],{"class":312,"line":460},[374,756,757],{"class":573},"    nrows",[374,759,448],{"class":408},[374,761,762],{"class":412},"size,\n",[374,764,765],{"class":312,"line":471},[374,766,457],{"class":412},[374,768,769,771,774,777,780,782,784,787,789,792],{"class":312,"line":482},[374,770,631],{"class":454},[374,772,773],{"class":412},"(window[",[374,775,776],{"class":383},"\"order_id\"",[374,778,779],{"class":412},"].iloc[[",[374,781,59],{"class":454},[374,783,21],{"class":412},[374,785,786],{"class":408},"-",[374,788,135],{"class":454},[374,790,791],{"class":412},"]].tolist())  ",[374,793,794],{"class":650},"# [1001, 1500]\n",[10,796,797,798,801,802,805],{},"If you pass ",[14,799,800],{},"skiprows=1000"," as a plain integer instead, pandas skips the first thousand ",[592,803,804],{},"file"," rows including the header, and the first surviving data row becomes the column names. That is correct when the sheet has a title block above the header and wrong here, so reach for the integer form only when you mean \"the table starts lower down\".",[37,807,46,813,46,816,46,819,46,823,46,827,46,835,46,839,46,842,46,846,46,849,46,852,46,860,46,865,46,871,46,875,46,879,46,882,46,885,46,889,46,892,46,895,46,899,46,903,46,907,46,910,46,913,46,917,46,920,46,925,46,929,46,932,46,934,46,937,46,941,46,944,46,947,46,951],{"viewBox":808,"role":40,"ariaLabelledBy":809,"xmlns":44,"style":812},"4 0 752 256",[810,811],"rows-which-t","rows-which-d","width:100%;max-width:752px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif",[48,814,815],{"id":810},"Choosing the right row parameter",[52,817,818],{"id":811},"If you want rows from the top, use nrows. For a block in the middle, use skiprows as a range starting at 1 plus nrows. For a pattern such as every tenth row, pass a callable to skiprows. For rows at the bottom, use skipfooter to drop trailers or count rows with openpyxl to read the tail.",[56,820],{"x":207,"y":59,"width":821,"height":822,"fill":62},"752","256",[56,824],{"x":327,"y":66,"width":825,"height":826,"rx":329,"fill":138,"stroke":139,"style":317},"280.0","75.5",[79,828,830],{"transform":829},"translate(368.0,29.0) scale(1.000)",[83,831],{"d":832,"fill":86,"stroke":833,"style":834},"M4 4h16v16H4z M4 9h16 M4 14h16 M10 4v16","var(--brand-strong,#4338ca)","stroke-width:1.80px;stroke-linecap:round;stroke-linejoin:round",[90,836,838],{"x":355,"y":826,"style":837},"font-size:13.5px;font-weight:700;fill:var(--brand-strong,#4338ca);text-anchor:middle","Which rows do you need?",[312,840],{"x1":355,"y1":841,"x2":355,"y2":328,"stroke":139,"style":317},"91.5",[312,843],{"x1":844,"y1":328,"x2":845,"y2":328,"stroke":139,"style":317},"104.0","656.0",[312,847],{"x1":844,"y1":328,"x2":844,"y2":848,"stroke":139,"style":317},"157.5",[319,850],{"points":851,"fill":322},"104.0,161.5 99.0,152.5 109.0,152.5",[56,853],{"x":854,"y":855,"width":856,"height":857,"rx":858,"fill":62,"stroke":71,"style":859},"74.3","121.5","59.4","21.0","10","stroke-width:1.2px",[90,861,864],{"x":844,"y":862,"style":863},"136.0","font-size:11.5px;font-weight:700;fill:var(--muted,#5b6780);text-anchor:middle","the top",[56,866],{"x":867,"y":868,"width":869,"height":870,"rx":329,"fill":210,"stroke":211,"style":317},"20.0","163.5","168.0","76.5",[90,872,874],{"x":844,"y":873,"style":334},"197.8","nrows=N",[90,876,878],{"x":844,"y":877,"style":343},"217.2","stops early with openpyxl",[312,880],{"x1":881,"y1":328,"x2":881,"y2":848,"stroke":139,"style":317},"288.0",[319,883],{"points":884,"fill":322},"288.0,161.5 283.0,152.5 293.0,152.5",[56,886],{"x":887,"y":855,"width":888,"height":857,"rx":858,"fill":62,"stroke":71,"style":859},"257.9","60.3",[90,890,891],{"x":881,"y":862,"style":863},"a block",[56,893],{"x":894,"y":868,"width":869,"height":870,"rx":329,"fill":138,"stroke":139,"style":317},"204.0",[90,896,898],{"x":881,"y":897,"style":837},"189.0","skiprows=range(1,",[90,900,902],{"x":881,"y":901,"style":837},"206.5","k)",[90,904,906],{"x":881,"y":905,"style":343},"226.0","plus nrows=N",[312,908],{"x1":909,"y1":328,"x2":909,"y2":848,"stroke":139,"style":317},"472.0",[319,911],{"points":912,"fill":322},"472.0,161.5 467.0,152.5 477.0,152.5",[56,914],{"x":915,"y":855,"width":916,"height":857,"rx":858,"fill":62,"stroke":71,"style":859},"436.5","71.0",[90,918,919],{"x":909,"y":862,"style":863},"a pattern",[56,921],{"x":922,"y":868,"width":869,"height":870,"rx":329,"fill":923,"stroke":924,"style":317},"388.0","#fdefd8","var(--gold,#b4740a)",[90,926,928],{"x":909,"y":873,"style":927},"font-size:13.5px;font-weight:700;fill:var(--gold-ink,#7a4e06);text-anchor:middle","skiprows=callable",[90,930,931],{"x":909,"y":877,"style":343},"every nth row, a sample",[312,933],{"x1":845,"y1":328,"x2":845,"y2":848,"stroke":139,"style":317},[319,935],{"points":936,"fill":322},"656.0,161.5 651.0,152.5 661.0,152.5",[56,938],{"x":939,"y":855,"width":940,"height":857,"rx":858,"fill":62,"stroke":71,"style":859},"614.9","82.3",[90,942,943],{"x":845,"y":862,"style":863},"the bottom",[56,945],{"x":946,"y":868,"width":869,"height":870,"rx":329,"fill":163,"stroke":164,"style":317},"572.0",[90,948,950],{"x":845,"y":873,"style":949},"font-size:13.5px;font-weight:700;fill:var(--accent-ink,#be185d);text-anchor:middle","skipfooter or a count",[90,952,953],{"x":845,"y":877,"style":343},"trailers or the tail",[360,955,957],{"id":956},"step-3-every-nth-row-or-a-sample-a-callable","Step 3 — Every nth row or a sample: a callable",[10,959,960,962,963,966],{},[14,961,24],{}," also takes a function. pandas calls it with each file row index and skips the row when it returns ",[14,964,965],{},"True",". Keep row 0 so the header survives, and you can express any pattern:",[365,968,970],{"className":399,"code":969,"language":401,"meta":370,"style":370},"every_tenth = pd.read_excel(\n    \"orders.xlsx\",\n    skiprows=lambda i: i > 0 and i % 10 != 0,\n)\nprint(len(every_tenth))                 # 6000\nprint(every_tenth[\"order_id\"].head(3).tolist())  # [10, 20, 30]\n",[14,971,972,981,987,1022,1026,1040],{"__ignoreMap":370},[374,973,974,977,979],{"class":312,"line":376},[374,975,976],{"class":412},"every_tenth ",[374,978,448],{"class":408},[374,980,717],{"class":412},[374,982,983,985],{"class":312,"line":422},[374,984,722],{"class":383},[374,986,725],{"class":412},[374,988,989,991,994,997,1000,1003,1006,1009,1012,1015,1018,1020],{"class":312,"line":435},[374,990,730],{"class":573},[374,992,993],{"class":408},"=lambda",[374,995,996],{"class":412}," i: i ",[374,998,999],{"class":408},">",[374,1001,1002],{"class":454}," 0",[374,1004,1005],{"class":408}," and",[374,1007,1008],{"class":412}," i ",[374,1010,1011],{"class":408},"%",[374,1013,1014],{"class":454}," 10",[374,1016,1017],{"class":408}," !=",[374,1019,1002],{"class":454},[374,1021,725],{"class":412},[374,1023,1024],{"class":312,"line":442},[374,1025,457],{"class":412},[374,1027,1028,1030,1032,1034,1037],{"class":312,"line":460},[374,1029,631],{"class":454},[374,1031,641],{"class":412},[374,1033,644],{"class":454},[374,1035,1036],{"class":412},"(every_tenth))                 ",[374,1038,1039],{"class":650},"# 6000\n",[374,1041,1042,1044,1047,1049,1052,1054,1057],{"class":312,"line":471},[374,1043,631],{"class":454},[374,1045,1046],{"class":412},"(every_tenth[",[374,1048,776],{"class":383},[374,1050,1051],{"class":412},"].head(",[374,1053,185],{"class":454},[374,1055,1056],{"class":412},").tolist())  ",[374,1058,1059],{"class":650},"# [10, 20, 30]\n",[10,1061,1062],{},"A random sample works the same way. Decide the kept positions first, so the choice is reproducible, and let the callable test membership:",[365,1064,1066],{"className":399,"code":1065,"language":401,"meta":370,"style":370},"keep = set(rng.choice(np.arange(1, n + 1), size=1_000, replace=False).tolist())\nsample = pd.read_excel(\"orders.xlsx\", skiprows=lambda i: i > 0 and i not in keep)\nprint(len(sample))  # 1000\n",[14,1067,1068,1112,1148],{"__ignoreMap":370},[374,1069,1070,1073,1075,1078,1081,1083,1085,1087,1089,1092,1095,1097,1100,1102,1105,1107,1109],{"class":312,"line":376},[374,1071,1072],{"class":412},"keep ",[374,1074,448],{"class":408},[374,1076,1077],{"class":454}," set",[374,1079,1080],{"class":412},"(rng.choice(np.arange(",[374,1082,135],{"class":454},[374,1084,493],{"class":412},[374,1086,496],{"class":408},[374,1088,499],{"class":454},[374,1090,1091],{"class":412},"), ",[374,1093,1094],{"class":573},"size",[374,1096,448],{"class":408},[374,1098,1099],{"class":454},"1_000",[374,1101,21],{"class":412},[374,1103,1104],{"class":573},"replace",[374,1106,448],{"class":408},[374,1108,579],{"class":454},[374,1110,1111],{"class":412},").tolist())\n",[374,1113,1114,1117,1119,1121,1123,1125,1127,1129,1131,1133,1135,1137,1139,1142,1145],{"class":312,"line":422},[374,1115,1116],{"class":412},"sample ",[374,1118,448],{"class":408},[374,1120,614],{"class":412},[374,1122,568],{"class":383},[374,1124,21],{"class":412},[374,1126,24],{"class":573},[374,1128,993],{"class":408},[374,1130,996],{"class":412},[374,1132,999],{"class":408},[374,1134,1002],{"class":454},[374,1136,1005],{"class":408},[374,1138,1008],{"class":412},[374,1140,1141],{"class":408},"not",[374,1143,1144],{"class":408}," in",[374,1146,1147],{"class":412}," keep)\n",[374,1149,1150,1152,1154,1156,1159],{"class":312,"line":435},[374,1151,631],{"class":454},[374,1153,641],{"class":412},[374,1155,644],{"class":454},[374,1157,1158],{"class":412},"(sample))  ",[374,1160,1161],{"class":650},"# 1000\n",[10,1163,1164],{},"Sampling this way is useful for developing a transformation against realistic data without waiting for the full read on every run. It does not make the read itself faster, though: pandas still walks every row to ask the callable about it.",[360,1166,1168],{"id":1167},"step-4-rows-at-the-bottom-skipfooter-and-the-tail","Step 4 — Rows at the bottom: skipfooter and the tail",[10,1170,1171,1172,1174],{},"Exports from accounting and ERP systems often end with a trailer — \"Report generated 06:00\", a grand-total row, a disclaimer. ",[14,1173,28],{}," drops a fixed number of rows from the bottom:",[365,1176,1178],{"className":399,"code":1177,"language":401,"meta":370,"style":370},"with_trailer = pd.concat(\n    [orders.head(8), pd.DataFrame({\"order_id\": [\"Total\"], \"amount\": [orders[\"amount\"].head(8).sum()]})],\n    ignore_index=True,\n)\nwith_trailer.to_excel(\"with_trailer.xlsx\", index=False)\n\nclean = pd.read_excel(\"with_trailer.xlsx\", skipfooter=1)\nprint(clean[\"order_id\"].tolist())  # 1 … 8, no \"Total\"\n",[14,1179,1180,1190,1226,1237,1241,1259,1263,1284],{"__ignoreMap":370},[374,1181,1182,1185,1187],{"class":312,"line":376},[374,1183,1184],{"class":412},"with_trailer ",[374,1186,448],{"class":408},[374,1188,1189],{"class":412}," pd.concat(\n",[374,1191,1192,1195,1197,1200,1202,1205,1208,1211,1214,1217,1219,1221,1223],{"class":312,"line":422},[374,1193,1194],{"class":412},"    [orders.head(",[374,1196,69],{"class":454},[374,1198,1199],{"class":412},"), pd.DataFrame({",[374,1201,776],{"class":383},[374,1203,1204],{"class":412},": [",[374,1206,1207],{"class":383},"\"Total\"",[374,1209,1210],{"class":412},"], ",[374,1212,1213],{"class":383},"\"amount\"",[374,1215,1216],{"class":412},": [orders[",[374,1218,1213],{"class":383},[374,1220,1051],{"class":412},[374,1222,69],{"class":454},[374,1224,1225],{"class":412},").sum()]})],\n",[374,1227,1228,1231,1233,1235],{"class":312,"line":435},[374,1229,1230],{"class":573},"    ignore_index",[374,1232,448],{"class":408},[374,1234,965],{"class":454},[374,1236,725],{"class":412},[374,1238,1239],{"class":312,"line":442},[374,1240,457],{"class":412},[374,1242,1243,1246,1249,1251,1253,1255,1257],{"class":312,"line":460},[374,1244,1245],{"class":412},"with_trailer.to_excel(",[374,1247,1248],{"class":383},"\"with_trailer.xlsx\"",[374,1250,21],{"class":412},[374,1252,574],{"class":573},[374,1254,448],{"class":408},[374,1256,579],{"class":454},[374,1258,457],{"class":412},[374,1260,1261],{"class":312,"line":471},[374,1262,439],{"emptyLinePlaceholder":438},[374,1264,1265,1268,1270,1272,1274,1276,1278,1280,1282],{"class":312,"line":482},[374,1266,1267],{"class":412},"clean ",[374,1269,448],{"class":408},[374,1271,614],{"class":412},[374,1273,1248],{"class":383},[374,1275,21],{"class":412},[374,1277,28],{"class":573},[374,1279,448],{"class":408},[374,1281,135],{"class":454},[374,1283,457],{"class":412},[374,1285,1286,1288,1291,1293,1296],{"class":312,"line":505},[374,1287,631],{"class":454},[374,1289,1290],{"class":412},"(clean[",[374,1292,776],{"class":383},[374,1294,1295],{"class":412},"].tolist())  ",[374,1297,1298],{"class":650},"# 1 … 8, no \"Total\"\n",[10,1300,1301,1302,1305],{},"Reading the ",[592,1303,1304],{},"last"," N rows is different, because an xlsx file stores rows top to bottom and there is no way to jump to the end. Count the rows cheaply first with openpyxl's read-only mode, then skip everything before the tail:",[365,1307,1309],{"className":399,"code":1308,"language":401,"meta":370,"style":370},"from openpyxl import load_workbook\n\nwb = load_workbook(\"orders.xlsx\", read_only=True)\ntotal_rows = wb.active.max_row          # includes the header row\nwb.close()\n\ntail_size = 100\ntail = pd.read_excel(\"orders.xlsx\", skiprows=range(1, total_rows - tail_size))\nprint(tail[\"order_id\"].iloc[[0, -1]].tolist())  # [59901, 60000]\n",[14,1310,1311,1324,1328,1351,1364,1369,1373,1383,1414],{"__ignoreMap":370},[374,1312,1313,1316,1319,1321],{"class":312,"line":376},[374,1314,1315],{"class":408},"from",[374,1317,1318],{"class":412}," openpyxl ",[374,1320,409],{"class":408},[374,1322,1323],{"class":412}," load_workbook\n",[374,1325,1326],{"class":312,"line":422},[374,1327,439],{"emptyLinePlaceholder":438},[374,1329,1330,1333,1335,1338,1340,1342,1345,1347,1349],{"class":312,"line":435},[374,1331,1332],{"class":412},"wb ",[374,1334,448],{"class":408},[374,1336,1337],{"class":412}," load_workbook(",[374,1339,568],{"class":383},[374,1341,21],{"class":412},[374,1343,1344],{"class":573},"read_only",[374,1346,448],{"class":408},[374,1348,965],{"class":454},[374,1350,457],{"class":412},[374,1352,1353,1356,1358,1361],{"class":312,"line":442},[374,1354,1355],{"class":412},"total_rows ",[374,1357,448],{"class":408},[374,1359,1360],{"class":412}," wb.active.max_row          ",[374,1362,1363],{"class":650},"# includes the header row\n",[374,1365,1366],{"class":312,"line":460},[374,1367,1368],{"class":412},"wb.close()\n",[374,1370,1371],{"class":312,"line":471},[374,1372,439],{"emptyLinePlaceholder":438},[374,1374,1375,1378,1380],{"class":312,"line":482},[374,1376,1377],{"class":412},"tail_size ",[374,1379,448],{"class":408},[374,1381,1382],{"class":454}," 100\n",[374,1384,1385,1388,1390,1392,1394,1396,1398,1400,1402,1404,1406,1409,1411],{"class":312,"line":505},[374,1386,1387],{"class":412},"tail ",[374,1389,448],{"class":408},[374,1391,614],{"class":412},[374,1393,568],{"class":383},[374,1395,21],{"class":412},[374,1397,24],{"class":573},[374,1399,448],{"class":408},[374,1401,735],{"class":454},[374,1403,641],{"class":412},[374,1405,135],{"class":454},[374,1407,1408],{"class":412},", total_rows ",[374,1410,786],{"class":408},[374,1412,1413],{"class":412}," tail_size))\n",[374,1415,1416,1418,1421,1423,1425,1427,1429,1431,1433,1435],{"class":312,"line":535},[374,1417,631],{"class":454},[374,1419,1420],{"class":412},"(tail[",[374,1422,776],{"class":383},[374,1424,779],{"class":412},[374,1426,59],{"class":454},[374,1428,21],{"class":412},[374,1430,786],{"class":408},[374,1432,135],{"class":454},[374,1434,791],{"class":412},[374,1436,1437],{"class":650},"# [59901, 60000]\n",[10,1439,1440,1441,1444,1445,1448,1449,666],{},"In read-only mode ",[14,1442,1443],{},"max_row"," comes from the dimension record the writing program stored in the file. Excel and pandas write it correctly; a few third-party exporters write a wrong or missing one. If the count looks implausible, call ",[14,1446,1447],{},"ws.reset_dimensions()"," and iterate to count, or read the whole sheet once — for a logging workbook that grows by appending, a trailing slice is usually cheaper to keep in a separate \"latest\" sheet anyway. For pulling out rows based on hidden or filtered state rather than position, see ",[31,1450,1452],{"href":1451},"\u002Fadvanced-data-transformation-and-cleaning\u002Fextracting-data-from-messy-excel-sheets\u002Fskip-hidden-and-filtered-rows-when-reading-excel\u002F","Skip Hidden and Filtered Rows When Reading Excel",[360,1454,1456],{"id":1455},"which-slices-are-actually-faster","Which slices are actually faster",[10,1458,1459,1460,1463,1464,1466],{},"A slice is always smaller once loaded. Whether it is ",[592,1461,1462],{},"faster"," depends on the engine and on where the slice sits. With the default openpyxl engine, pandas stops parsing once ",[14,1465,20],{}," rows have been collected, so reading from the top is close to free. Skipping rows still parses them — the parser has to read a row to know it is a row — so a window near the end costs almost as much as the whole sheet.",[37,1468,46,1474,46,1477,46,1480,46,1484,46,1487,46,1493,46,1497,46,1502,46,1505,46,1509,46,1511,46,1513,46,1516,46,1520,46,1523,46,1528,46,1530,46,1534,46,1537,46,1542,46,1545,46,1549,46,1552,46,1556],{"viewBox":1469,"role":40,"ariaLabelledBy":1470,"xmlns":44,"style":1473},"4 0 732 246",[1471,1472],"rows-speed-t","rows-speed-d","width:100%;max-width:732px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif",[48,1475,1476],{"id":1471},"Time to read slices of a 60,000-row sheet",[52,1478,1479],{"id":1472},"With the openpyxl engine the full sheet took 0.71 seconds, the first 100 rows took 0.006 seconds, and the last 100 rows via skiprows took 0.71 seconds. With calamine the full sheet took 0.12 seconds and the first 100 rows 0.066 seconds.",[56,1481],{"x":207,"y":59,"width":1482,"height":1483,"fill":62},"732","246",[56,1485],{"x":867,"y":66,"width":1486,"height":130,"rx":275,"fill":70,"stroke":71,"style":101},"228.9",[90,1488,1492],{"x":1489,"y":1490,"style":1491},"134.5","34.5","font-size:12.5px;font-weight:700;fill:var(--text,#172033);text-anchor:middle","openpyxl, whole sheet",[56,1494],{"x":1495,"y":66,"width":1496,"height":130,"rx":275,"fill":163,"stroke":164,"style":72},"258.9","417.2",[90,1498,1501],{"x":1499,"y":1490,"style":1500},"684.1","font-size:12px;font-weight:700;fill:var(--accent-ink,#be185d);text-anchor:start","0.71 s",[56,1503],{"x":867,"y":1504,"width":1486,"height":130,"rx":275,"fill":70,"stroke":71,"style":101},"56.0",[90,1506,1508],{"x":1489,"y":1507,"style":1491},"74.5","openpyxl, last 100 via skiprows",[56,1510],{"x":1495,"y":1504,"width":1496,"height":130,"rx":275,"fill":163,"stroke":164,"style":72},[90,1512,1501],{"x":1499,"y":1507,"style":1500},[56,1514],{"x":867,"y":1515,"width":1486,"height":130,"rx":275,"fill":70,"stroke":71,"style":101},"96.0",[90,1517,1519],{"x":1489,"y":1518,"style":1491},"114.5","openpyxl, first 100 (nrows)",[56,1521],{"x":1495,"y":1515,"width":1522,"height":130,"rx":275,"fill":210,"stroke":211,"style":72},"6.0",[90,1524,1527],{"x":1525,"y":1518,"style":1526},"272.9","font-size:12px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:start","0.006 s",[56,1529],{"x":867,"y":862,"width":1486,"height":130,"rx":275,"fill":70,"stroke":71,"style":101},[90,1531,1533],{"x":1489,"y":1532,"style":1491},"154.5","calamine, whole sheet",[56,1535],{"x":1495,"y":862,"width":1536,"height":130,"rx":275,"fill":923,"stroke":924,"style":72},"70.5",[90,1538,1541],{"x":1539,"y":1532,"style":1540},"337.4","font-size:12px;font-weight:700;fill:var(--gold-ink,#7a4e06);text-anchor:start","0.12 s",[56,1543],{"x":867,"y":1544,"width":1486,"height":130,"rx":275,"fill":70,"stroke":71,"style":101},"176.0",[90,1546,1548],{"x":1489,"y":1547,"style":1491},"194.5","calamine, first 100 (nrows)",[56,1550],{"x":1495,"y":1544,"width":1551,"height":130,"rx":275,"fill":923,"stroke":924,"style":72},"38.8",[90,1553,1555],{"x":1554,"y":1547,"style":1540},"305.7","0.066 s",[90,1557,1558],{"x":355,"y":905,"style":357},"measured on the 60,000-row workbook above; absolute times vary by machine, the ratios hold",[10,1560,1561],{},"You can reproduce the comparison on your own machine:",[365,1563,1565],{"className":399,"code":1564,"language":401,"meta":370,"style":370},"import time\n\ndef timed(**kwargs):\n    t0 = time.perf_counter()\n    frame = pd.read_excel(\"orders.xlsx\", **kwargs)\n    return round(time.perf_counter() - t0, 3), len(frame)\n\nprint(\"full      \", timed())\nprint(\"first 100 \", timed(nrows=100))\nprint(\"last 100  \", timed(skiprows=range(1, total_rows - 100)))\nprint(\"calamine  \", timed(engine=\"calamine\"))\n",[14,1566,1567,1574,1578,1595,1605,1623,1648,1652,1664,1686,1717],{"__ignoreMap":370},[374,1568,1569,1571],{"class":312,"line":376},[374,1570,409],{"class":408},[374,1572,1573],{"class":412}," time\n",[374,1575,1576],{"class":312,"line":422},[374,1577,439],{"emptyLinePlaceholder":438},[374,1579,1580,1583,1587,1589,1592],{"class":312,"line":435},[374,1581,1582],{"class":408},"def",[374,1584,1586],{"class":1585},"s_Opv"," timed",[374,1588,641],{"class":412},[374,1590,1591],{"class":408},"**",[374,1593,1594],{"class":412},"kwargs):\n",[374,1596,1597,1600,1602],{"class":312,"line":442},[374,1598,1599],{"class":412},"    t0 ",[374,1601,448],{"class":408},[374,1603,1604],{"class":412}," time.perf_counter()\n",[374,1606,1607,1610,1612,1614,1616,1618,1620],{"class":312,"line":460},[374,1608,1609],{"class":412},"    frame ",[374,1611,448],{"class":408},[374,1613,614],{"class":412},[374,1615,568],{"class":383},[374,1617,21],{"class":412},[374,1619,1591],{"class":408},[374,1621,1622],{"class":412},"kwargs)\n",[374,1624,1625,1628,1631,1634,1636,1639,1641,1643,1645],{"class":312,"line":471},[374,1626,1627],{"class":408},"    return",[374,1629,1630],{"class":454}," round",[374,1632,1633],{"class":412},"(time.perf_counter() ",[374,1635,786],{"class":408},[374,1637,1638],{"class":412}," t0, ",[374,1640,185],{"class":454},[374,1642,1091],{"class":412},[374,1644,644],{"class":454},[374,1646,1647],{"class":412},"(frame)\n",[374,1649,1650],{"class":312,"line":482},[374,1651,439],{"emptyLinePlaceholder":438},[374,1653,1654,1656,1658,1661],{"class":312,"line":505},[374,1655,631],{"class":454},[374,1657,641],{"class":412},[374,1659,1660],{"class":383},"\"full      \"",[374,1662,1663],{"class":412},", timed())\n",[374,1665,1666,1668,1670,1673,1676,1678,1680,1683],{"class":312,"line":535},[374,1667,631],{"class":454},[374,1669,641],{"class":412},[374,1671,1672],{"class":383},"\"first 100 \"",[374,1674,1675],{"class":412},", timed(",[374,1677,20],{"class":573},[374,1679,448],{"class":408},[374,1681,1682],{"class":454},"100",[374,1684,1685],{"class":412},"))\n",[374,1687,1688,1690,1692,1695,1697,1699,1701,1703,1705,1707,1709,1711,1714],{"class":312,"line":556},[374,1689,631],{"class":454},[374,1691,641],{"class":412},[374,1693,1694],{"class":383},"\"last 100  \"",[374,1696,1675],{"class":412},[374,1698,24],{"class":573},[374,1700,448],{"class":408},[374,1702,735],{"class":454},[374,1704,641],{"class":412},[374,1706,135],{"class":454},[374,1708,1408],{"class":412},[374,1710,786],{"class":408},[374,1712,1713],{"class":454}," 100",[374,1715,1716],{"class":412},")))\n",[374,1718,1719,1721,1723,1726,1728,1731,1733,1736],{"class":312,"line":562},[374,1720,631],{"class":454},[374,1722,641],{"class":412},[374,1724,1725],{"class":383},"\"calamine  \"",[374,1727,1675],{"class":412},[374,1729,1730],{"class":573},"engine",[374,1732,448],{"class":408},[374,1734,1735],{"class":383},"\"calamine\"",[374,1737,1685],{"class":412},[10,1739,1740,1741,1743,1744,1746,1747,666],{},"The calamine engine, a Rust reader, loads the entire sheet before pandas sees it, so ",[14,1742,20],{}," saves memory but little time — yet its full read is several times faster than openpyxl's anyway. For previews of the top, openpyxl with ",[14,1745,20],{}," wins; for anything that needs the whole sheet or its tail, calamine wins. Both are covered in ",[31,1748,1750],{"href":1749},"\u002Fadvanced-data-transformation-and-cleaning\u002Freading-excel-with-polars-and-arrow\u002Fspeed-up-pandas-excel-reads-with-the-calamine-engine\u002F","Speed Up pandas Excel Reads with the calamine Engine",[360,1752,1754],{"id":1753},"common-pitfalls","Common pitfalls",[1756,1757,1758,1768,1784,1795],"ul",{},[1759,1760,1761,1764,1765,1767],"li",{},[681,1762,1763],{},"Off-by-one windows."," ",[14,1766,24],{}," counts file rows from zero with the header at 0; Excel counts from one. Row 1,001 in Excel is file position 1,000. Print the first and last id of every window while you develop, as the examples above do.",[1759,1769,1770,1764,1776,1779,1780,1783],{},[681,1771,1772,1773,1775],{},"Integer ",[14,1774,24],{}," eats the header.",[14,1777,1778],{},"skiprows=5"," removes file rows 0–4, header included. Use ",[14,1781,1782],{},"range(1, 6)"," to keep the header and drop five data rows.",[1759,1785,1786,1791,1792,1794],{},[681,1787,1788,1790],{},[14,1789,28],{}," with trailing blank rows."," Blank rows at the bottom are usually trimmed by the reader before ",[14,1793,28],{}," applies, but formatted empty cells can count as rows. If the wrong rows disappear, read without it and drop the trailer by value instead.",[1759,1796,1797,1800,1801,1804,1805,1809],{},[681,1798,1799],{},"Slicing before deduplicating."," A window of rows is not a window of ",[592,1802,1803],{},"records"," when a sheet has one record spread over several rows. Fix the structure first — ",[31,1806,1808],{"href":1807},"\u002Fadvanced-data-transformation-and-cleaning\u002Fextracting-data-from-messy-excel-sheets\u002Fparse-records-that-span-multiple-rows-in-excel\u002F","Parse Records That Span Multiple Rows in an Excel Sheet"," shows how.",[360,1811,1813],{"id":1812},"performance-and-scale-notes","Performance and scale notes",[10,1815,1816,1817,1820,1821,666],{},"For workbooks in the hundreds of thousands of rows, combine a row slice with ",[14,1818,1819],{},"usecols"," — fewer columns cut parsing time as well as memory, and the two options compose. When you repeatedly need different slices of the same large file, convert it once to Parquet and slice that instead: Parquet reads a row range or a column subset without parsing the rest, which no Excel reader can do. The trade-offs are covered in ",[31,1822,1824],{"href":1823},"\u002Fadvanced-data-transformation-and-cleaning\u002Fworking-with-large-excel-files-in-python\u002F","Working with Large Excel Files in Python",[360,1826,1828],{"id":1827},"conclusion","Conclusion",[10,1830,1831,1833,1834,1836,1837,1839,1840,1842],{},[14,1832,20],{}," takes rows from the top and, with openpyxl, stops reading early. ",[14,1835,24],{}," as a range starting at 1 plus ",[14,1838,20],{}," takes a window; as a callable it takes any pattern; as a plain integer it moves the header down. ",[14,1841,28],{}," trims trailers, and a quick read-only row count gives you the tail. Only the top slice saves parsing time, so when the rows you need live at the end of a very large sheet, change the file format or the engine rather than the parameters.",[360,1844,1846],{"id":1845},"frequently-asked-questions","Frequently asked questions",[10,1848,1849,1852],{},[681,1850,1851],{},"Does nrows make read_excel faster?","\nWith the openpyxl engine, yes — it stops reading the sheet once it has the rows you asked for, so the first hundred rows of a huge sheet load almost instantly. The calamine engine loads the whole sheet first, so nrows mainly saves memory there.",[10,1854,1855,1858],{},[681,1856,1857],{},"Is the header row counted by nrows?","\nNo. nrows counts data rows after the header. nrows=10 returns ten rows plus the column names taken from the header row.",[10,1860,1861,1864,1865,1868],{},[681,1862,1863],{},"Are skiprows numbers zero-based?","\nYes, and they are positions in the file, header included. Row 1 in Excel is index 0, so skiprows=",[374,1866,1867],{},"1, 2"," drops the first two data rows under a header on Excel row 1.",[10,1870,1871,1874],{},[681,1872,1873],{},"How do I read the last 100 rows without loading the whole sheet?","\nYou cannot avoid touching the whole sheet, because xlsx stores rows in order. Get the row count cheaply with openpyxl in read-only mode, then pass skiprows=range(1, total - 100) to read_excel.",[10,1876,1877,1880],{},[681,1878,1879],{},"Can I filter rows by value while reading?","\nNo. read_excel has no row filter. Read the columns you need with usecols, then filter the DataFrame — or stream rows with openpyxl and keep only the ones that match.",[360,1882,1884],{"id":1883},"related","Related",[1756,1886,1887,1893,1900,1907],{},[1759,1888,1889,1890,1892],{},"Up one level: ",[31,1891,34],{"href":33}," — every read_excel option in context.",[1759,1894,1895,1899],{},[31,1896,1898],{"href":1897},"\u002Fgetting-started-with-python-excel-automation\u002Freading-excel-files-with-pandas\u002Fread-specific-columns-from-excel-with-pandas\u002F","Read Specific Columns From Excel With Pandas"," — the column-wise counterpart to this guide.",[1759,1901,1902,1906],{},[31,1903,1905],{"href":1904},"\u002Fadvanced-data-transformation-and-cleaning\u002Fworking-with-large-excel-files-in-python\u002Fread-large-excel-file-in-chunks-with-pandas\u002F","Read a Large Excel File in Chunks with pandas"," — process a whole sheet slice by slice.",[1759,1908,1909,1911],{},[31,1910,665],{"href":664}," — when the table starts lower down.",[1913,1914,1915],"style",{},"html pre.shiki code .sMTad, html code.shiki .sMTad{--shiki-default:#6F42C1;--shiki-dark:#FFB757}html pre.shiki code .srMev, html code.shiki .srMev{--shiki-default:#032F62;--shiki-dark:#ADDCFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s-kum, html code.shiki .s-kum{--shiki-default:#D73A49;--shiki-dark:#FF9492}html pre.shiki code .skGVy, html code.shiki .skGVy{--shiki-default:#24292E;--shiki-dark:#F0F3F6}html pre.shiki code .sP0c6, html code.shiki .sP0c6{--shiki-default:#005CC5;--shiki-dark:#91CBFF}html pre.shiki code .sa561, html code.shiki .sa561{--shiki-default:#E36209;--shiki-dark:#FFB757}html pre.shiki code .s-wDw, html code.shiki .s-wDw{--shiki-default:#6A737D;--shiki-dark:#BDC4CC}html pre.shiki code .s_Opv, html code.shiki .s_Opv{--shiki-default:#6F42C1;--shiki-dark:#DBB7FF}",{"title":370,"searchDepth":422,"depth":422,"links":1917},[1918,1919,1920,1921,1922,1923,1924,1925,1926,1927,1928],{"id":362,"depth":422,"text":363},{"id":584,"depth":422,"text":585},{"id":669,"depth":422,"text":670},{"id":956,"depth":422,"text":957},{"id":1167,"depth":422,"text":1168},{"id":1455,"depth":422,"text":1456},{"id":1753,"depth":422,"text":1754},{"id":1812,"depth":422,"text":1813},{"id":1827,"depth":422,"text":1828},{"id":1845,"depth":422,"text":1846},{"id":1883,"depth":422,"text":1884},"2026-09-23","Read the first rows, a window in the middle, every nth row or the last rows of an Excel sheet with pandas — nrows, skiprows, skipfooter, and which of them actually saves time.","md",[1933,1935,1937,1939,1941],{"q":1851,"a":1934},"With the openpyxl engine, yes — it stops reading the sheet once it has the rows you asked for, so the first hundred rows of a huge sheet load almost instantly. The calamine engine loads the whole sheet first, so nrows mainly saves memory there.",{"q":1857,"a":1936},"No. nrows counts data rows after the header. nrows=10 returns ten rows plus the column names taken from the header row.",{"q":1863,"a":1938},"Yes, and they are positions in the file, header included. Row 1 in Excel is index 0, so skiprows=[1, 2] drops the first two data rows under a header on Excel row 1.",{"q":1873,"a":1940},"You cannot avoid touching the whole sheet, because xlsx stores rows in order. Get the row count cheaply with openpyxl in read-only mode, then pass skiprows=range(1, total - 100) to read_excel.",{"q":1879,"a":1942},"No. read_excel has no row filter. Read the columns you need with usecols, then filter the DataFrame — or stream rows with openpyxl and keep only the ones that match.","read only some rows of an excel file with pandas",null,{"breadcrumb":1946},[1947,1950,1953],{"name":1948,"item":1949},"Home","\u002F",{"name":1951,"item":1952},"Getting Started with Python Excel Automation","\u002Fgetting-started-with-python-excel-automation\u002F",{"name":1954,"item":33},"Reading Excel Files with Pandas","\u002Fgetting-started-with-python-excel-automation\u002Freading-excel-files-with-pandas\u002Fread-only-some-rows-of-an-excel-file-with-pandas",{"title":1957,"description":1958},"Read Only Some Rows of an Excel File with pandas (nrows, skiprows)","Load a slice of an Excel sheet with pandas read_excel — nrows for the top, skiprows for a window, callables for every nth row, skipfooter and openpyxl for the tail — with timings.","read-only-some-rows-of-an-excel-file-with-pandas","getting-started-with-python-excel-automation\u002Freading-excel-files-with-pandas\u002Fread-only-some-rows-of-an-excel-file-with-pandas\u002Findex",[1962,1963],"reading-excel","pandas","how-to","M19Wbi-0WquoJNvhfQPQ0jtthPpLJO1LiauUCnfQvhc",[1967,1971],{"title":1968,"path":1969,"stem":1970,"children":-1},"Read Excel Sheets Whose Names Change with pandas","\u002Fgetting-started-with-python-excel-automation\u002Freading-excel-files-with-pandas\u002Fread-excel-sheets-whose-names-change-with-pandas","getting-started-with-python-excel-automation\u002Freading-excel-files-with-pandas\u002Fread-excel-sheets-whose-names-change-with-pandas\u002Findex",{"title":1898,"path":1972,"stem":1973,"children":-1},"\u002Fgetting-started-with-python-excel-automation\u002Freading-excel-files-with-pandas\u002Fread-specific-columns-from-excel-with-pandas","getting-started-with-python-excel-automation\u002Freading-excel-files-with-pandas\u002Fread-specific-columns-from-excel-with-pandas\u002Findex",[1975,1977],{"path":1976,"title":1951},"\u002Fgetting-started-with-python-excel-automation",{"path":1978,"title":1954},"\u002Fgetting-started-with-python-excel-automation\u002Freading-excel-files-with-pandas",[],[1981,1984,1987,1990,1993,1996],{"path":1982,"title":1983,"kind":1964},"\u002Fgetting-started-with-python-excel-automation\u002Fhandling-excel-file-formats-and-conversions\u002Fread-an-excel-file-from-a-url-or-bytes-in-python","Read an Excel File from a URL or Bytes in Python",{"path":1985,"title":1986,"kind":1964},"\u002Fgetting-started-with-python-excel-automation\u002Fusing-openpyxl-for-excel-file-manipulation\u002Ffind-the-last-row-with-data-in-openpyxl","Find the Last Row with Data in openpyxl",{"path":1988,"title":1989,"kind":1964},"\u002Fgetting-started-with-python-excel-automation\u002Fusing-openpyxl-for-excel-file-manipulation\u002Fiterate-over-rows-and-columns-with-openpyxl","Iterate over Rows and Columns with openpyxl",{"path":1991,"title":1992,"kind":1964},"\u002Fgetting-started-with-python-excel-automation\u002Fusing-openpyxl-for-excel-file-manipulation\u002Fread-cell-value-from-excel-with-openpyxl","Read a Cell Value From Excel With openpyxl",{"path":1994,"title":1995,"kind":1964},"\u002Fadvanced-data-transformation-and-cleaning\u002Fcleaning-excel-data-with-pandas\u002Fstandardise-excel-column-names-with-pandas","Standardise Excel Column Names with pandas",{"path":1997,"title":1998,"kind":1999},"\u002Fadvanced-data-transformation-and-cleaning\u002Fextracting-data-from-messy-excel-sheets","Extracting Data from Messy Excel Sheets","guide",1790972065265]