[{"data":1,"prerenderedAt":2143},["ShallowReactive",2],{"doc:\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-this-sheet-is-too-large-error":3,"surround:\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-this-sheet-is-too-large-error":2107,"ancestors:\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-this-sheet-is-too-large-error":2116,"children:\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-this-sheet-is-too-large-error":2121,"related:\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-this-sheet-is-too-large-error":2122},{"id":4,"title":5,"body":6,"dateModified":2070,"datePublished":2070,"description":2071,"extension":2072,"faq":2073,"keyword":2084,"kind":2085,"meta":2086,"navigation":221,"path":2095,"seo":2096,"slug":2099,"stem":2100,"topics":2101,"type":2105,"__hash__":2106},"docs\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-this-sheet-is-too-large-error\u002Findex.md","Fix \"This sheet is too large\" When Writing Excel with pandas",{"type":7,"value":8,"toc":2058},"minimark",[9,13,24,33,143,148,177,180,299,303,323,326,517,524,528,531,834,841,845,848,1146,1158,1301,1305,1308,1553,1560,1564,1567,1787,1922,1925,1929,1980,1984,1987,1991,1997,2003,2009,2015,2021,2025,2054],[10,11,12],"p",{},"Exporting a big DataFrame ends with:",[14,15,21],"pre",{"className":16,"code":18,"language":19,"meta":20},[17],"language-text","ValueError: This sheet is too large! Your sheet size is: 1500000, 4 Max sheet size is: 1048576, 16384\n","text","",[22,23,18],"code",{"__ignoreMap":20},[10,25,26,27,32],{},"The message is precise. An Excel worksheet is a fixed grid of 1,048,576 rows by 16,384 columns, and pandas checks the frame's shape against it before writing. The first number pair is your frame — rows, then columns — and the second is the limit. The fix depends on who needs the data and why, so answer that before reaching for code. This guide, part of ",[28,29,31],"a",{"href":30},"\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002F","Troubleshooting Common Python Excel Errors",", covers splitting long and wide frames, a boundary case where rows are lost with no error at all, and when to stop using Excel for the job.",[34,35,43,44,43,48,43,52,43,60,43,70,43,76,43,83,43,88,43,91,43,95,43,100,43,105,43,108,43,112,43,116,43,120,43,123,43,127,43,132,43,137],"svg",{"viewBox":36,"role":37,"ariaLabelledBy":38,"xmlns":41,"style":42},"4 0 744 206","img",[39,40],"big-limits-t","big-limits-d","http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg","width:100%;max-width:744px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif","\n  ",[45,46,47],"title",{"id":39},"Excel's grid limits compared with a large export",[49,50,51],"desc",{"id":40},"A worksheet holds 1,048,576 rows including the header, so 1,048,575 data rows at most. An export of 1,500,000 rows exceeds that and must be split into two sheets, or delivered in a format without a row limit.",[53,54],"rect",{"x":55,"y":56,"width":57,"height":58,"fill":59},"4","0","744","206","#ffffff",[53,61],{"x":62,"y":63,"width":64,"height":65,"rx":66,"fill":67,"stroke":68,"style":69},"20.0","16.0","192.3","28.0","7","#e7ebef","var(--line,#cdd5e6)","stroke-width:1px",[19,71,75],{"x":72,"y":73,"style":74},"116.2","34.5","font-size:12.5px;font-weight:700;fill:var(--text,#172033);text-anchor:middle","Export to write",[53,77],{"x":78,"y":63,"width":79,"height":65,"rx":66,"fill":80,"stroke":81,"style":82},"222.3","403.9","#fee8f2","var(--accent,#f43f8f)","stroke-width:1.5px",[19,84,87],{"x":85,"y":73,"style":86},"634.2","font-size:12px;font-weight:700;fill:var(--accent-ink,#be185d);text-anchor:start","1,500,000 rows",[53,89],{"x":62,"y":90,"width":64,"height":65,"rx":66,"fill":67,"stroke":68,"style":69},"56.0",[19,92,94],{"x":72,"y":93,"style":74},"74.5","One worksheet",[53,96],{"x":78,"y":90,"width":97,"height":65,"rx":66,"fill":98,"stroke":99,"style":82},"282.4","#f0f4ff","var(--brand,#5b5cf0)",[19,101,104],{"x":102,"y":93,"style":103},"512.7","font-size:12px;font-weight:700;fill:var(--brand-strong,#4338ca);text-anchor:start","1,048,576 rows",[53,106],{"x":62,"y":107,"width":64,"height":65,"rx":66,"fill":67,"stroke":68,"style":69},"96.0",[19,109,111],{"x":72,"y":110,"style":74},"114.5","Data rows under a header",[53,113],{"x":78,"y":107,"width":97,"height":65,"rx":66,"fill":114,"stroke":115,"style":82},"#d9f4f1","var(--teal,#0f9488)",[19,117,119],{"x":102,"y":110,"style":118},"font-size:12px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:start","1,048,575 rows",[53,121],{"x":62,"y":122,"width":64,"height":65,"rx":66,"fill":67,"stroke":68,"style":69},"136.0",[19,124,126],{"x":72,"y":125,"style":74},"154.5","Legacy .xls sheet",[53,128],{"x":78,"y":122,"width":129,"height":65,"rx":66,"fill":130,"stroke":131,"style":82},"17.6","#fdefd8","var(--gold,#b4740a)",[19,133,136],{"x":134,"y":125,"style":135},"248.0","font-size:12px;font-weight:700;fill:var(--gold-ink,#7a4e06);text-anchor:start","65,536 rows",[19,138,142],{"x":139,"y":140,"style":141},"380.0","186.0","font-size:12.5px;font-weight:400;fill:var(--muted,#5b6780);text-anchor:middle","16,384 columns is the other limit; legacy .xls files allow only 256",[144,145,147],"h2",{"id":146},"prerequisites","Prerequisites",[14,149,153],{"className":150,"code":151,"language":152,"meta":20,"style":20},"language-bash shiki shiki-themes github-light github-dark-high-contrast","pip install pandas xlsxwriter pyarrow\n","bash",[22,154,155],{"__ignoreMap":20},[156,157,160,164,168,171,174],"span",{"class":158,"line":159},"line",1,[156,161,163],{"class":162},"sMTad","pip",[156,165,167],{"class":166},"srMev"," install",[156,169,170],{"class":166}," pandas",[156,172,173],{"class":166}," xlsxwriter",[156,175,176],{"class":166}," pyarrow\n",[10,178,179],{},"The examples use a modest frame and a deliberately tiny \"limit\" so they run in seconds; the logic is the same at full size.",[14,181,185],{"className":182,"code":183,"language":184,"meta":20,"style":20},"language-python shiki shiki-themes github-light github-dark-high-contrast","import numpy as np\nimport pandas as pd\n\nMAX_ROWS = 1_048_576          # rows per worksheet, header included\nMAX_COLS = 16_384\n\ndf = pd.DataFrame({\"id\": np.arange(25), \"value\": np.arange(25) * 1.5})\n","python",[22,186,187,203,216,223,240,251,256],{"__ignoreMap":20},[156,188,189,193,197,200],{"class":158,"line":159},[156,190,192],{"class":191},"s-kum","import",[156,194,196],{"class":195},"skGVy"," numpy ",[156,198,199],{"class":191},"as",[156,201,202],{"class":195}," np\n",[156,204,206,208,211,213],{"class":158,"line":205},2,[156,207,192],{"class":191},[156,209,210],{"class":195}," pandas ",[156,212,199],{"class":191},[156,214,215],{"class":195}," pd\n",[156,217,219],{"class":158,"line":218},3,[156,220,222],{"emptyLinePlaceholder":221},true,"\n",[156,224,226,230,233,236],{"class":158,"line":225},4,[156,227,229],{"class":228},"sP0c6","MAX_ROWS",[156,231,232],{"class":191}," =",[156,234,235],{"class":228}," 1_048_576",[156,237,239],{"class":238},"s-wDw","          # rows per worksheet, header included\n",[156,241,243,246,248],{"class":158,"line":242},5,[156,244,245],{"class":228},"MAX_COLS",[156,247,232],{"class":191},[156,249,250],{"class":228}," 16_384\n",[156,252,254],{"class":158,"line":253},6,[156,255,222],{"emptyLinePlaceholder":221},[156,257,259,262,265,268,271,274,277,280,283,285,287,290,293,296],{"class":158,"line":258},7,[156,260,261],{"class":195},"df ",[156,263,264],{"class":191},"=",[156,266,267],{"class":195}," pd.DataFrame({",[156,269,270],{"class":166},"\"id\"",[156,272,273],{"class":195},": np.arange(",[156,275,276],{"class":228},"25",[156,278,279],{"class":195},"), ",[156,281,282],{"class":166},"\"value\"",[156,284,273],{"class":195},[156,286,276],{"class":228},[156,288,289],{"class":195},") ",[156,291,292],{"class":191},"*",[156,294,295],{"class":228}," 1.5",[156,297,298],{"class":195},"})\n",[144,300,302],{"id":301},"step-1-mind-the-header-the-silent-off-by-one","Step 1 — Mind the header: the silent off-by-one",[10,304,305,306,309,310,313,314,318,319,322],{},"pandas checks ",[22,307,308],{},"len(df)"," — the data rows — against 1,048,576. But ",[22,311,312],{},"to_excel"," also writes a header row, so the real capacity is one row less. A frame of ",[315,316,317],"em",{},"exactly"," 1,048,576 rows therefore passes the check and does not fit. With the openpyxl engine the write then fails with a different message (",[22,320,321],{},"Row numbers must be between 1 and 1048576","); with the xlsxwriter engine it succeeds, and the last data row is simply not in the file. No error, no warning.",[10,324,325],{},"Check the real capacity yourself before writing, counting every row the export will occupy:",[14,327,329],{"className":182,"code":328,"language":184,"meta":20,"style":20},"def rows_needed(frame: pd.DataFrame, header: bool = True, startrow: int = 0) -> int:\n    header_rows = frame.columns.nlevels if header else 0\n    return startrow + header_rows + len(frame)\n\ndef fits_one_sheet(frame: pd.DataFrame, **kwargs) -> bool:\n    return rows_needed(frame, **kwargs) \u003C= MAX_ROWS and frame.shape[1] \u003C= MAX_COLS\n\nprint(fits_one_sheet(df))                                   # True\nprint(rows_needed(pd.DataFrame(index=range(MAX_ROWS))))     # 1048577 -> does not fit\n",[22,330,331,370,392,414,418,438,473,477,489],{"__ignoreMap":20},[156,332,333,336,340,343,346,348,351,354,357,359,362,365,367],{"class":158,"line":159},[156,334,335],{"class":191},"def",[156,337,339],{"class":338},"s_Opv"," rows_needed",[156,341,342],{"class":195},"(frame: pd.DataFrame, header: ",[156,344,345],{"class":228},"bool",[156,347,232],{"class":191},[156,349,350],{"class":228}," True",[156,352,353],{"class":195},", startrow: ",[156,355,356],{"class":228},"int",[156,358,232],{"class":191},[156,360,361],{"class":228}," 0",[156,363,364],{"class":195},") -> ",[156,366,356],{"class":228},[156,368,369],{"class":195},":\n",[156,371,372,375,377,380,383,386,389],{"class":158,"line":205},[156,373,374],{"class":195},"    header_rows ",[156,376,264],{"class":191},[156,378,379],{"class":195}," frame.columns.nlevels ",[156,381,382],{"class":191},"if",[156,384,385],{"class":195}," header ",[156,387,388],{"class":191},"else",[156,390,391],{"class":228}," 0\n",[156,393,394,397,400,403,406,408,411],{"class":158,"line":218},[156,395,396],{"class":191},"    return",[156,398,399],{"class":195}," startrow ",[156,401,402],{"class":191},"+",[156,404,405],{"class":195}," header_rows ",[156,407,402],{"class":191},[156,409,410],{"class":228}," len",[156,412,413],{"class":195},"(frame)\n",[156,415,416],{"class":158,"line":225},[156,417,222],{"emptyLinePlaceholder":221},[156,419,420,422,425,428,431,434,436],{"class":158,"line":242},[156,421,335],{"class":191},[156,423,424],{"class":338}," fits_one_sheet",[156,426,427],{"class":195},"(frame: pd.DataFrame, ",[156,429,430],{"class":191},"**",[156,432,433],{"class":195},"kwargs) -> ",[156,435,345],{"class":228},[156,437,369],{"class":195},[156,439,440,442,445,447,450,453,456,459,462,465,468,470],{"class":158,"line":253},[156,441,396],{"class":191},[156,443,444],{"class":195}," rows_needed(frame, ",[156,446,430],{"class":191},[156,448,449],{"class":195},"kwargs) ",[156,451,452],{"class":191},"\u003C=",[156,454,455],{"class":228}," MAX_ROWS",[156,457,458],{"class":191}," and",[156,460,461],{"class":195}," frame.shape[",[156,463,464],{"class":228},"1",[156,466,467],{"class":195},"] ",[156,469,452],{"class":191},[156,471,472],{"class":228}," MAX_COLS\n",[156,474,475],{"class":158,"line":258},[156,476,222],{"emptyLinePlaceholder":221},[156,478,480,483,486],{"class":158,"line":479},8,[156,481,482],{"class":228},"print",[156,484,485],{"class":195},"(fits_one_sheet(df))                                   ",[156,487,488],{"class":238},"# True\n",[156,490,492,494,497,501,503,506,509,511,514],{"class":158,"line":491},9,[156,493,482],{"class":228},[156,495,496],{"class":195},"(rows_needed(pd.DataFrame(",[156,498,500],{"class":499},"sa561","index",[156,502,264],{"class":191},[156,504,505],{"class":228},"range",[156,507,508],{"class":195},"(",[156,510,229],{"class":228},[156,512,513],{"class":195},"))))     ",[156,515,516],{"class":238},"# 1048577 -> does not fit\n",[10,518,519,520,523],{},"The helper also accounts for ",[22,521,522],{},"startrow"," and for MultiIndex column headers, which take more than one row. Put this check in front of every export that can grow, and route oversized frames to Step 2 or Step 4.",[144,525,527],{"id":526},"step-2-split-long-frames-across-sheets","Step 2 — Split long frames across sheets",[10,529,530],{},"When one reader needs everything in one workbook, split the rows into blocks that each fit under a header, and name the sheets so the order is obvious:",[14,532,534],{"className":182,"code":533,"language":184,"meta":20,"style":20},"def write_split(frame: pd.DataFrame, path: str, base: str = \"data\", per_sheet: int = MAX_ROWS - 1) -> list[str]:\n    names = []\n    with pd.ExcelWriter(path, engine=\"xlsxwriter\") as writer:\n        for part, start in enumerate(range(0, len(frame), per_sheet), start=1):\n            name = f\"{base}_{part}\"\n            frame.iloc[start:start + per_sheet].to_excel(writer, sheet_name=name, index=False)\n            names.append(name)\n    return names\n\nnames = write_split(df, \"split.xlsx\", per_sheet=10)       # tiny blocks to show the split\nprint(names)                                               # ['data_1', 'data_2', 'data_3']\nback = pd.concat(pd.read_excel(\"split.xlsx\", sheet_name=None).values(), ignore_index=True)\nprint(len(back) == len(df))                                # True\n",[22,535,536,582,592,615,656,692,720,725,732,736,766,777,812],{"__ignoreMap":20},[156,537,538,540,543,546,549,552,554,556,559,562,564,566,568,571,574,577,579],{"class":158,"line":159},[156,539,335],{"class":191},[156,541,542],{"class":338}," write_split",[156,544,545],{"class":195},"(frame: pd.DataFrame, path: ",[156,547,548],{"class":228},"str",[156,550,551],{"class":195},", base: ",[156,553,548],{"class":228},[156,555,232],{"class":191},[156,557,558],{"class":166}," \"data\"",[156,560,561],{"class":195},", per_sheet: ",[156,563,356],{"class":228},[156,565,232],{"class":191},[156,567,455],{"class":228},[156,569,570],{"class":191}," -",[156,572,573],{"class":228}," 1",[156,575,576],{"class":195},") -> list[",[156,578,548],{"class":228},[156,580,581],{"class":195},"]:\n",[156,583,584,587,589],{"class":158,"line":205},[156,585,586],{"class":195},"    names ",[156,588,264],{"class":191},[156,590,591],{"class":195}," []\n",[156,593,594,597,600,603,605,608,610,612],{"class":158,"line":218},[156,595,596],{"class":191},"    with",[156,598,599],{"class":195}," pd.ExcelWriter(path, ",[156,601,602],{"class":499},"engine",[156,604,264],{"class":191},[156,606,607],{"class":166},"\"xlsxwriter\"",[156,609,289],{"class":195},[156,611,199],{"class":191},[156,613,614],{"class":195}," writer:\n",[156,616,617,620,623,626,629,631,633,635,637,640,643,646,649,651,653],{"class":158,"line":225},[156,618,619],{"class":191},"        for",[156,621,622],{"class":195}," part, start ",[156,624,625],{"class":191},"in",[156,627,628],{"class":228}," enumerate",[156,630,508],{"class":195},[156,632,505],{"class":228},[156,634,508],{"class":195},[156,636,56],{"class":228},[156,638,639],{"class":195},", ",[156,641,642],{"class":228},"len",[156,644,645],{"class":195},"(frame), per_sheet), ",[156,647,648],{"class":499},"start",[156,650,264],{"class":191},[156,652,464],{"class":228},[156,654,655],{"class":195},"):\n",[156,657,658,661,663,666,669,673,676,679,682,684,687,689],{"class":158,"line":242},[156,659,660],{"class":195},"            name ",[156,662,264],{"class":191},[156,664,665],{"class":191}," f",[156,667,668],{"class":166},"\"",[156,670,672],{"class":671},"sSjpA","{",[156,674,675],{"class":195},"base",[156,677,678],{"class":671},"}",[156,680,681],{"class":166},"_",[156,683,672],{"class":671},[156,685,686],{"class":195},"part",[156,688,678],{"class":671},[156,690,691],{"class":166},"\"\n",[156,693,694,697,699,702,705,707,710,712,714,717],{"class":158,"line":253},[156,695,696],{"class":195},"            frame.iloc[start:start ",[156,698,402],{"class":191},[156,700,701],{"class":195}," per_sheet].to_excel(writer, ",[156,703,704],{"class":499},"sheet_name",[156,706,264],{"class":191},[156,708,709],{"class":195},"name, ",[156,711,500],{"class":499},[156,713,264],{"class":191},[156,715,716],{"class":228},"False",[156,718,719],{"class":195},")\n",[156,721,722],{"class":158,"line":258},[156,723,724],{"class":195},"            names.append(name)\n",[156,726,727,729],{"class":158,"line":479},[156,728,396],{"class":191},[156,730,731],{"class":195}," names\n",[156,733,734],{"class":158,"line":491},[156,735,222],{"emptyLinePlaceholder":221},[156,737,739,742,744,747,750,752,755,757,760,763],{"class":158,"line":738},10,[156,740,741],{"class":195},"names ",[156,743,264],{"class":191},[156,745,746],{"class":195}," write_split(df, ",[156,748,749],{"class":166},"\"split.xlsx\"",[156,751,639],{"class":195},[156,753,754],{"class":499},"per_sheet",[156,756,264],{"class":191},[156,758,759],{"class":228},"10",[156,761,762],{"class":195},")       ",[156,764,765],{"class":238},"# tiny blocks to show the split\n",[156,767,769,771,774],{"class":158,"line":768},11,[156,770,482],{"class":228},[156,772,773],{"class":195},"(names)                                               ",[156,775,776],{"class":238},"# ['data_1', 'data_2', 'data_3']\n",[156,778,780,783,785,788,790,792,794,796,799,802,805,807,810],{"class":158,"line":779},12,[156,781,782],{"class":195},"back ",[156,784,264],{"class":191},[156,786,787],{"class":195}," pd.concat(pd.read_excel(",[156,789,749],{"class":166},[156,791,639],{"class":195},[156,793,704],{"class":499},[156,795,264],{"class":191},[156,797,798],{"class":228},"None",[156,800,801],{"class":195},").values(), ",[156,803,804],{"class":499},"ignore_index",[156,806,264],{"class":191},[156,808,809],{"class":228},"True",[156,811,719],{"class":195},[156,813,815,817,819,821,824,827,829,832],{"class":158,"line":814},13,[156,816,482],{"class":228},[156,818,508],{"class":195},[156,820,642],{"class":228},[156,822,823],{"class":195},"(back) ",[156,825,826],{"class":191},"==",[156,828,410],{"class":228},[156,830,831],{"class":195},"(df))                                ",[156,833,488],{"class":238},[10,835,836,837,840],{},"The read-back check is worth keeping at full size: it proves no row was lost at a boundary. For very large splits, add ",[22,838,839],{},"engine_kwargs={\"options\": {\"constant_memory\": True}}"," to the writer so xlsxwriter streams rows to disk instead of holding the whole workbook in memory.",[144,842,844],{"id":843},"step-3-wide-frames-the-column-limit","Step 3 — Wide frames: the column limit",[10,846,847],{},"The second limit is 16,384 columns. Frames that wide usually come from a pivot with a high-cardinality column — one column per customer or per day for years. Two fixes: pivot the long dimension onto the rows instead, or split the columns into groups across sheets while repeating the key column on each:",[14,849,851],{"className":182,"code":850,"language":184,"meta":20,"style":20},"wide = pd.DataFrame(np.ones((3, 40)), columns=[f\"day_{i:03}\" for i in range(40)])\nwide.insert(0, \"store\", [\"A\", \"B\", \"C\"])\n\ndef split_columns(frame, key, per_sheet, path):\n    value_cols = [c for c in frame.columns if c != key]\n    with pd.ExcelWriter(path, engine=\"xlsxwriter\") as writer:\n        for n, start in enumerate(range(0, len(value_cols), per_sheet), start=1):\n            cols = [key] + value_cols[start:start + per_sheet]\n            frame[cols].to_excel(writer, sheet_name=f\"cols_{n}\", index=False)\n\nsplit_columns(wide, \"store\", per_sheet=15, path=\"wide.xlsx\")\nprint(pd.ExcelFile(\"wide.xlsx\").sheet_names)   # ['cols_1', 'cols_2', 'cols_3']\n",[22,852,853,918,949,953,963,994,1012,1046,1066,1099,1103,1131],{"__ignoreMap":20},[156,854,855,858,860,863,866,868,871,874,877,879,882,885,888,890,893,896,898,900,903,906,908,911,913,915],{"class":158,"line":159},[156,856,857],{"class":195},"wide ",[156,859,264],{"class":191},[156,861,862],{"class":195}," pd.DataFrame(np.ones((",[156,864,865],{"class":228},"3",[156,867,639],{"class":195},[156,869,870],{"class":228},"40",[156,872,873],{"class":195},")), ",[156,875,876],{"class":499},"columns",[156,878,264],{"class":191},[156,880,881],{"class":195},"[",[156,883,884],{"class":191},"f",[156,886,887],{"class":166},"\"day_",[156,889,672],{"class":671},[156,891,892],{"class":195},"i",[156,894,895],{"class":191},":03",[156,897,678],{"class":671},[156,899,668],{"class":166},[156,901,902],{"class":191}," for",[156,904,905],{"class":195}," i ",[156,907,625],{"class":191},[156,909,910],{"class":228}," range",[156,912,508],{"class":195},[156,914,870],{"class":228},[156,916,917],{"class":195},")])\n",[156,919,920,923,925,927,930,933,936,938,941,943,946],{"class":158,"line":205},[156,921,922],{"class":195},"wide.insert(",[156,924,56],{"class":228},[156,926,639],{"class":195},[156,928,929],{"class":166},"\"store\"",[156,931,932],{"class":195},", [",[156,934,935],{"class":166},"\"A\"",[156,937,639],{"class":195},[156,939,940],{"class":166},"\"B\"",[156,942,639],{"class":195},[156,944,945],{"class":166},"\"C\"",[156,947,948],{"class":195},"])\n",[156,950,951],{"class":158,"line":218},[156,952,222],{"emptyLinePlaceholder":221},[156,954,955,957,960],{"class":158,"line":225},[156,956,335],{"class":191},[156,958,959],{"class":338}," split_columns",[156,961,962],{"class":195},"(frame, key, per_sheet, path):\n",[156,964,965,968,970,973,976,979,981,984,986,988,991],{"class":158,"line":242},[156,966,967],{"class":195},"    value_cols ",[156,969,264],{"class":191},[156,971,972],{"class":195}," [c ",[156,974,975],{"class":191},"for",[156,977,978],{"class":195}," c ",[156,980,625],{"class":191},[156,982,983],{"class":195}," frame.columns ",[156,985,382],{"class":191},[156,987,978],{"class":195},[156,989,990],{"class":191},"!=",[156,992,993],{"class":195}," key]\n",[156,995,996,998,1000,1002,1004,1006,1008,1010],{"class":158,"line":253},[156,997,596],{"class":191},[156,999,599],{"class":195},[156,1001,602],{"class":499},[156,1003,264],{"class":191},[156,1005,607],{"class":166},[156,1007,289],{"class":195},[156,1009,199],{"class":191},[156,1011,614],{"class":195},[156,1013,1014,1016,1019,1021,1023,1025,1027,1029,1031,1033,1035,1038,1040,1042,1044],{"class":158,"line":258},[156,1015,619],{"class":191},[156,1017,1018],{"class":195}," n, start ",[156,1020,625],{"class":191},[156,1022,628],{"class":228},[156,1024,508],{"class":195},[156,1026,505],{"class":228},[156,1028,508],{"class":195},[156,1030,56],{"class":228},[156,1032,639],{"class":195},[156,1034,642],{"class":228},[156,1036,1037],{"class":195},"(value_cols), per_sheet), ",[156,1039,648],{"class":499},[156,1041,264],{"class":191},[156,1043,464],{"class":228},[156,1045,655],{"class":195},[156,1047,1048,1051,1053,1056,1058,1061,1063],{"class":158,"line":479},[156,1049,1050],{"class":195},"            cols ",[156,1052,264],{"class":191},[156,1054,1055],{"class":195}," [key] ",[156,1057,402],{"class":191},[156,1059,1060],{"class":195}," value_cols[start:start ",[156,1062,402],{"class":191},[156,1064,1065],{"class":195}," per_sheet]\n",[156,1067,1068,1071,1073,1075,1077,1080,1082,1085,1087,1089,1091,1093,1095,1097],{"class":158,"line":491},[156,1069,1070],{"class":195},"            frame[cols].to_excel(writer, ",[156,1072,704],{"class":499},[156,1074,264],{"class":191},[156,1076,884],{"class":191},[156,1078,1079],{"class":166},"\"cols_",[156,1081,672],{"class":671},[156,1083,1084],{"class":195},"n",[156,1086,678],{"class":671},[156,1088,668],{"class":166},[156,1090,639],{"class":195},[156,1092,500],{"class":499},[156,1094,264],{"class":191},[156,1096,716],{"class":228},[156,1098,719],{"class":195},[156,1100,1101],{"class":158,"line":738},[156,1102,222],{"emptyLinePlaceholder":221},[156,1104,1105,1108,1110,1112,1114,1116,1119,1121,1124,1126,1129],{"class":158,"line":768},[156,1106,1107],{"class":195},"split_columns(wide, ",[156,1109,929],{"class":166},[156,1111,639],{"class":195},[156,1113,754],{"class":499},[156,1115,264],{"class":191},[156,1117,1118],{"class":228},"15",[156,1120,639],{"class":195},[156,1122,1123],{"class":499},"path",[156,1125,264],{"class":191},[156,1127,1128],{"class":166},"\"wide.xlsx\"",[156,1130,719],{"class":195},[156,1132,1133,1135,1138,1140,1143],{"class":158,"line":779},[156,1134,482],{"class":228},[156,1136,1137],{"class":195},"(pd.ExcelFile(",[156,1139,1128],{"class":166},[156,1141,1142],{"class":195},").sheet_names)   ",[156,1144,1145],{"class":238},"# ['cols_1', 'cols_2', 'cols_3']\n",[10,1147,1148,1149,1152,1153,1157],{},"Most of the time, though, a frame with thousands of columns is better ",[315,1150,1151],{},"melted"," back to a long table — one row per store and day — which is easier to filter and pivot in Excel anyway; see ",[28,1154,1156],{"href":1155},"\u002Fadvanced-data-transformation-and-cleaning\u002Fcreating-pivot-tables-from-excel-data\u002Funpivot-a-wide-excel-sheet-with-pandas-melt\u002F","Unpivot a Wide Excel Sheet with pandas melt",".",[34,1159,43,1165,43,1168,43,1171,43,1175,43,1182,43,1192,43,1196,43,1200,43,1204,43,1207,43,1212,43,1219,43,1223,43,1228,43,1234,43,1238,43,1243,43,1245,43,1248,43,1252,43,1255,43,1258,43,1265,43,1269,43,1272,43,1274,43,1277,43,1281,43,1284,43,1287,43,1294,43,1298],{"viewBox":1160,"role":37,"ariaLabelledBy":1161,"xmlns":41,"style":1164},"4 0 752 272",[1162,1163],"big-choose-t","big-choose-d","width:100%;max-width:752px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif",[45,1166,1167],{"id":1162},"What to do with a DataFrame that does not fit a worksheet",[49,1169,1170],{"id":1163},"If a person needs all the rows in Excel, split them across sheets. If the frame is too wide, melt it to a long table or split columns with the key repeated. If the data feeds another system or is too large to use in Excel, deliver CSV or Parquet with an Excel summary.",[53,1172],{"x":55,"y":56,"width":1173,"height":1174,"fill":59},"752","272",[53,1176],{"x":1177,"y":63,"width":1178,"height":1179,"rx":1180,"fill":98,"stroke":99,"style":1181},"240.0","280.0","75.5","12","stroke-width:2px",[1183,1184,1186],"g",{"transform":1185},"translate(368.0,29.0) scale(1.000)",[1123,1187],{"d":1188,"fill":1189,"stroke":1190,"style":1191},"M9 11a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7z M2.5 20c0-3.6 2.9-6 6.5-6s6.5 2.4 6.5 6 M16 4.5a3.3 3.3 0 0 1 0 6.3 M18 14.3c2.2.7 3.5 2.8 3.5 5.7","none","var(--brand-strong,#4338ca)","stroke-width:1.80px;stroke-linecap:round;stroke-linejoin:round",[19,1193,1195],{"x":139,"y":1179,"style":1194},"font-size:13.5px;font-weight:700;fill:var(--brand-strong,#4338ca);text-anchor:middle","Who needs the full data?",[158,1197],{"x1":139,"y1":1198,"x2":139,"y2":1199,"stroke":99,"style":1181},"91.5","111.5",[158,1201],{"x1":1202,"y1":1199,"x2":1203,"y2":1199,"stroke":99,"style":1181},"134.7","625.3",[158,1205],{"x1":1202,"y1":1199,"x2":1202,"y2":1206,"stroke":99,"style":1181},"157.5",[1208,1209],"polygon",{"points":1210,"fill":1211},"134.7,161.5 129.7,152.5 139.7,152.5","#5b5cf0",[53,1213],{"x":1214,"y":1215,"width":1216,"height":1217,"rx":759,"fill":59,"stroke":68,"style":1218},"73.8","121.5","121.7","21.0","stroke-width:1.2px",[19,1220,1222],{"x":1202,"y":122,"style":1221},"font-size:11.5px;font-weight:700;fill:var(--muted,#5b6780);text-anchor:middle","a person, in Excel",[53,1224],{"x":62,"y":1225,"width":1226,"height":1227,"rx":1180,"fill":98,"stroke":99,"style":1181},"163.5","229.3","93.0",[1183,1229,1231],{"transform":1230},"translate(122.7,176.5) scale(1.000)",[1123,1232],{"d":1233,"fill":1189,"stroke":1190,"style":1191},"M12 3l9 5-9 5-9-5z M3 13l9 5 9-5 M3 17l9 5 9-5",[19,1235,1237],{"x":1202,"y":1236,"style":1194},"223.0","Split across sheets",[19,1239,1242],{"x":1202,"y":1240,"style":1241},"242.5","font-size:11.5px;font-weight:400;fill:var(--text,#172033);text-anchor:middle","blocks of 1,048,575",[158,1244],{"x1":139,"y1":1199,"x2":139,"y2":1206,"stroke":99,"style":1181},[1208,1246],{"points":1247,"fill":1211},"380.0,161.5 375.0,152.5 385.0,152.5",[53,1249],{"x":1250,"y":1215,"width":1251,"height":1217,"rx":759,"fill":59,"stroke":68,"style":1218},"316.8","126.4",[19,1253,1254],{"x":139,"y":122,"style":1221},"too many columns",[53,1256],{"x":1257,"y":1225,"width":1226,"height":1227,"rx":1180,"fill":130,"stroke":131,"style":1181},"265.3",[1183,1259,1261],{"transform":1260},"translate(368.0,176.5) scale(1.000)",[1123,1262],{"d":1263,"fill":1189,"stroke":1264,"style":1191},"M3 5h18v14H3z M3 10h18 M3 15h18 M9 5v14","var(--gold-ink,#7a4e06)",[19,1266,1268],{"x":139,"y":1236,"style":1267},"font-size:13.5px;font-weight:700;fill:var(--gold-ink,#7a4e06);text-anchor:middle","Melt or split columns",[19,1270,1271],{"x":139,"y":1240,"style":1241},"key repeated",[158,1273],{"x1":1203,"y1":1199,"x2":1203,"y2":1206,"stroke":99,"style":1181},[1208,1275],{"points":1276,"fill":1211},"625.3,161.5 620.3,152.5 630.3,152.5",[53,1278],{"x":1279,"y":1215,"width":1280,"height":1217,"rx":759,"fill":59,"stroke":68,"style":1218},"570.2","110.3",[19,1282,1283],{"x":1203,"y":122,"style":1221},"another system",[53,1285],{"x":1286,"y":1225,"width":1226,"height":1227,"rx":1180,"fill":114,"stroke":115,"style":1181},"510.7",[1183,1288,1290],{"transform":1289},"translate(613.3,176.5) scale(1.000)",[1123,1291],{"d":1292,"fill":1189,"stroke":1293,"style":1191},"M5 6c0-1.7 3.1-3 7-3s7 1.3 7 3-3.1 3-7 3-7-1.3-7-3z M5 6v12c0 1.7 3.1 3 7 3s7-1.3 7-3V6 M5 12c0 1.7 3.1 3 7 3s7-1.3 7-3","var(--teal-ink,#0b6157)",[19,1295,1297],{"x":1203,"y":1236,"style":1296},"font-size:13.5px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:middle","CSV or Parquet",[19,1299,1300],{"x":1203,"y":1240,"style":1241},"plus an Excel summary",[144,1302,1304],{"id":1303},"step-4-summarise-in-excel-deliver-detail-elsewhere","Step 4 — Summarise in Excel, deliver detail elsewhere",[10,1306,1307],{},"A million-row sheet is technically possible and practically poor: it takes a long time to open, filters are sluggish, and nobody reads it row by row. Ask what the reader does with the data. Usually they need a summary — totals by month, top customers, exceptions — and the full detail only for occasional lookups or for loading into another tool. Give them both, each in the right format:",[14,1309,1311],{"className":182,"code":1310,"language":184,"meta":20,"style":20},"detail = pd.DataFrame({\n    \"month\": np.repeat(pd.period_range(\"2026-01\", periods=5, freq=\"M\").astype(str), 5),\n    \"amount\": np.arange(25) * 10.0,\n})\ndetail.to_parquet(\"detail.parquet\", index=False)          # full data, compact and typed\ndetail.to_csv(\"detail.csv\", index=False)                  # full data, opens anywhere\n\nsummary = detail.groupby(\"month\", as_index=False)[\"amount\"].sum()\nwith pd.ExcelWriter(\"summary.xlsx\", engine=\"xlsxwriter\") as writer:\n    summary.to_excel(writer, sheet_name=\"Summary\", index=False)\n    writer.sheets[\"Summary\"].write(len(summary) + 2, 0, \"Full detail: detail.parquet \u002F detail.csv\")\nprint(summary)\n",[22,1312,1313,1323,1366,1385,1389,1411,1433,1437,1468,1493,1515,1546],{"__ignoreMap":20},[156,1314,1315,1318,1320],{"class":158,"line":159},[156,1316,1317],{"class":195},"detail ",[156,1319,264],{"class":191},[156,1321,1322],{"class":195}," pd.DataFrame({\n",[156,1324,1325,1328,1331,1334,1336,1339,1341,1344,1346,1349,1351,1354,1357,1359,1361,1363],{"class":158,"line":205},[156,1326,1327],{"class":166},"    \"month\"",[156,1329,1330],{"class":195},": np.repeat(pd.period_range(",[156,1332,1333],{"class":166},"\"2026-01\"",[156,1335,639],{"class":195},[156,1337,1338],{"class":499},"periods",[156,1340,264],{"class":191},[156,1342,1343],{"class":228},"5",[156,1345,639],{"class":195},[156,1347,1348],{"class":499},"freq",[156,1350,264],{"class":191},[156,1352,1353],{"class":166},"\"M\"",[156,1355,1356],{"class":195},").astype(",[156,1358,548],{"class":228},[156,1360,279],{"class":195},[156,1362,1343],{"class":228},[156,1364,1365],{"class":195},"),\n",[156,1367,1368,1371,1373,1375,1377,1379,1382],{"class":158,"line":218},[156,1369,1370],{"class":166},"    \"amount\"",[156,1372,273],{"class":195},[156,1374,276],{"class":228},[156,1376,289],{"class":195},[156,1378,292],{"class":191},[156,1380,1381],{"class":228}," 10.0",[156,1383,1384],{"class":195},",\n",[156,1386,1387],{"class":158,"line":225},[156,1388,298],{"class":195},[156,1390,1391,1394,1397,1399,1401,1403,1405,1408],{"class":158,"line":242},[156,1392,1393],{"class":195},"detail.to_parquet(",[156,1395,1396],{"class":166},"\"detail.parquet\"",[156,1398,639],{"class":195},[156,1400,500],{"class":499},[156,1402,264],{"class":191},[156,1404,716],{"class":228},[156,1406,1407],{"class":195},")          ",[156,1409,1410],{"class":238},"# full data, compact and typed\n",[156,1412,1413,1416,1419,1421,1423,1425,1427,1430],{"class":158,"line":253},[156,1414,1415],{"class":195},"detail.to_csv(",[156,1417,1418],{"class":166},"\"detail.csv\"",[156,1420,639],{"class":195},[156,1422,500],{"class":499},[156,1424,264],{"class":191},[156,1426,716],{"class":228},[156,1428,1429],{"class":195},")                  ",[156,1431,1432],{"class":238},"# full data, opens anywhere\n",[156,1434,1435],{"class":158,"line":258},[156,1436,222],{"emptyLinePlaceholder":221},[156,1438,1439,1442,1444,1447,1450,1452,1455,1457,1459,1462,1465],{"class":158,"line":479},[156,1440,1441],{"class":195},"summary ",[156,1443,264],{"class":191},[156,1445,1446],{"class":195}," detail.groupby(",[156,1448,1449],{"class":166},"\"month\"",[156,1451,639],{"class":195},[156,1453,1454],{"class":499},"as_index",[156,1456,264],{"class":191},[156,1458,716],{"class":228},[156,1460,1461],{"class":195},")[",[156,1463,1464],{"class":166},"\"amount\"",[156,1466,1467],{"class":195},"].sum()\n",[156,1469,1470,1473,1476,1479,1481,1483,1485,1487,1489,1491],{"class":158,"line":491},[156,1471,1472],{"class":191},"with",[156,1474,1475],{"class":195}," pd.ExcelWriter(",[156,1477,1478],{"class":166},"\"summary.xlsx\"",[156,1480,639],{"class":195},[156,1482,602],{"class":499},[156,1484,264],{"class":191},[156,1486,607],{"class":166},[156,1488,289],{"class":195},[156,1490,199],{"class":191},[156,1492,614],{"class":195},[156,1494,1495,1498,1500,1502,1505,1507,1509,1511,1513],{"class":158,"line":738},[156,1496,1497],{"class":195},"    summary.to_excel(writer, ",[156,1499,704],{"class":499},[156,1501,264],{"class":191},[156,1503,1504],{"class":166},"\"Summary\"",[156,1506,639],{"class":195},[156,1508,500],{"class":499},[156,1510,264],{"class":191},[156,1512,716],{"class":228},[156,1514,719],{"class":195},[156,1516,1517,1520,1522,1525,1527,1530,1532,1535,1537,1539,1541,1544],{"class":158,"line":768},[156,1518,1519],{"class":195},"    writer.sheets[",[156,1521,1504],{"class":166},[156,1523,1524],{"class":195},"].write(",[156,1526,642],{"class":228},[156,1528,1529],{"class":195},"(summary) ",[156,1531,402],{"class":191},[156,1533,1534],{"class":228}," 2",[156,1536,639],{"class":195},[156,1538,56],{"class":228},[156,1540,639],{"class":195},[156,1542,1543],{"class":166},"\"Full detail: detail.parquet \u002F detail.csv\"",[156,1545,719],{"class":195},[156,1547,1548,1550],{"class":158,"line":779},[156,1549,482],{"class":228},[156,1551,1552],{"class":195},"(summary)\n",[10,1554,1555,1556,1157],{},"Parquet keeps types and compresses well, and pandas, Polars, DuckDB and Power BI read it directly; CSV opens anywhere, though Excel itself will only load the first 1,048,576 rows of it. The trade-offs are covered in ",[28,1557,1559],{"href":1558},"\u002Fgetting-started-with-python-excel-automation\u002Fchoosing-a-python-excel-library\u002Fexcel-vs-csv-vs-parquet-for-python-data-pipelines\u002F","Excel vs CSV vs Parquet for Python Data Pipelines",[144,1561,1563],{"id":1562},"step-5-guard-the-export-in-production","Step 5 — Guard the export in production",[10,1565,1566],{},"The error tends to appear months after a report goes live, when the data grows past the limit. A guard that checks size before writing and chooses the delivery accordingly turns a crash into a controlled change of format:",[14,1568,1570],{"className":182,"code":1569,"language":184,"meta":20,"style":20},"def export(frame: pd.DataFrame, path_stem: str) -> str:\n    if fits_one_sheet(frame):\n        frame.to_excel(f\"{path_stem}.xlsx\", index=False)\n        return f\"{path_stem}.xlsx\"\n    if frame.shape[1] \u003C= MAX_COLS and len(frame) \u003C= 5 * (MAX_ROWS - 1):\n        write_split(frame, f\"{path_stem}.xlsx\")\n        return f\"{path_stem}.xlsx (split)\"\n    frame.to_parquet(f\"{path_stem}.parquet\", index=False)\n    return f\"{path_stem}.parquet\"\n\nprint(export(df, \"orders\"))     # orders.xlsx\n",[22,1571,1572,1590,1598,1627,1645,1686,1705,1722,1750,1767,1771],{"__ignoreMap":20},[156,1573,1574,1576,1579,1582,1584,1586,1588],{"class":158,"line":159},[156,1575,335],{"class":191},[156,1577,1578],{"class":338}," export",[156,1580,1581],{"class":195},"(frame: pd.DataFrame, path_stem: ",[156,1583,548],{"class":228},[156,1585,364],{"class":195},[156,1587,548],{"class":228},[156,1589,369],{"class":195},[156,1591,1592,1595],{"class":158,"line":205},[156,1593,1594],{"class":191},"    if",[156,1596,1597],{"class":195}," fits_one_sheet(frame):\n",[156,1599,1600,1603,1605,1607,1609,1612,1614,1617,1619,1621,1623,1625],{"class":158,"line":218},[156,1601,1602],{"class":195},"        frame.to_excel(",[156,1604,884],{"class":191},[156,1606,668],{"class":166},[156,1608,672],{"class":671},[156,1610,1611],{"class":195},"path_stem",[156,1613,678],{"class":671},[156,1615,1616],{"class":166},".xlsx\"",[156,1618,639],{"class":195},[156,1620,500],{"class":499},[156,1622,264],{"class":191},[156,1624,716],{"class":228},[156,1626,719],{"class":195},[156,1628,1629,1632,1634,1636,1638,1640,1642],{"class":158,"line":225},[156,1630,1631],{"class":191},"        return",[156,1633,665],{"class":191},[156,1635,668],{"class":166},[156,1637,672],{"class":671},[156,1639,1611],{"class":195},[156,1641,678],{"class":671},[156,1643,1644],{"class":166},".xlsx\"\n",[156,1646,1647,1649,1651,1653,1655,1657,1660,1662,1664,1667,1669,1672,1675,1678,1680,1682,1684],{"class":158,"line":242},[156,1648,1594],{"class":191},[156,1650,461],{"class":195},[156,1652,464],{"class":228},[156,1654,467],{"class":195},[156,1656,452],{"class":191},[156,1658,1659],{"class":228}," MAX_COLS",[156,1661,458],{"class":191},[156,1663,410],{"class":228},[156,1665,1666],{"class":195},"(frame) ",[156,1668,452],{"class":191},[156,1670,1671],{"class":228}," 5",[156,1673,1674],{"class":191}," *",[156,1676,1677],{"class":195}," (",[156,1679,229],{"class":228},[156,1681,570],{"class":191},[156,1683,573],{"class":228},[156,1685,655],{"class":195},[156,1687,1688,1691,1693,1695,1697,1699,1701,1703],{"class":158,"line":253},[156,1689,1690],{"class":195},"        write_split(frame, ",[156,1692,884],{"class":191},[156,1694,668],{"class":166},[156,1696,672],{"class":671},[156,1698,1611],{"class":195},[156,1700,678],{"class":671},[156,1702,1616],{"class":166},[156,1704,719],{"class":195},[156,1706,1707,1709,1711,1713,1715,1717,1719],{"class":158,"line":258},[156,1708,1631],{"class":191},[156,1710,665],{"class":191},[156,1712,668],{"class":166},[156,1714,672],{"class":671},[156,1716,1611],{"class":195},[156,1718,678],{"class":671},[156,1720,1721],{"class":166},".xlsx (split)\"\n",[156,1723,1724,1727,1729,1731,1733,1735,1737,1740,1742,1744,1746,1748],{"class":158,"line":479},[156,1725,1726],{"class":195},"    frame.to_parquet(",[156,1728,884],{"class":191},[156,1730,668],{"class":166},[156,1732,672],{"class":671},[156,1734,1611],{"class":195},[156,1736,678],{"class":671},[156,1738,1739],{"class":166},".parquet\"",[156,1741,639],{"class":195},[156,1743,500],{"class":499},[156,1745,264],{"class":191},[156,1747,716],{"class":228},[156,1749,719],{"class":195},[156,1751,1752,1754,1756,1758,1760,1762,1764],{"class":158,"line":491},[156,1753,396],{"class":191},[156,1755,665],{"class":191},[156,1757,668],{"class":166},[156,1759,672],{"class":671},[156,1761,1611],{"class":195},[156,1763,678],{"class":671},[156,1765,1766],{"class":166},".parquet\"\n",[156,1768,1769],{"class":158,"line":738},[156,1770,222],{"emptyLinePlaceholder":221},[156,1772,1773,1775,1778,1781,1784],{"class":158,"line":768},[156,1774,482],{"class":228},[156,1776,1777],{"class":195},"(export(df, ",[156,1779,1780],{"class":166},"\"orders\"",[156,1782,1783],{"class":195},"))     ",[156,1785,1786],{"class":238},"# orders.xlsx\n",[34,1788,43,1793,43,1796,43,1799,43,1802,43,1806,43,1813,43,1819,43,1823,43,1831,43,1835,43,1840,43,1843,43,1846,43,1852,43,1856,43,1859,43,1863,43,1866,43,1870,43,1873,43,1876,43,1881,43,1885,43,1888,43,1892,43,1894,43,1898,43,1901,43,1904,43,1909,43,1913,43,1916,43,1920],{"viewBox":1789,"role":37,"ariaLabelledBy":1790,"xmlns":41,"style":1164},"4 0 752 133",[1791,1792],"big-guard-t","big-guard-d",[45,1794,1795],{"id":1791},"The export guard choosing a format by size",[49,1797,1798],{"id":1792},"The guard counts the rows the export needs including the header. If they fit one worksheet it writes one xlsx sheet. If they fit five worksheets it writes a split workbook. Otherwise it writes Parquet, and every run logs which branch was taken.",[53,1800],{"x":55,"y":56,"width":1173,"height":1801,"fill":59},"133",[53,1803],{"x":62,"y":63,"width":1804,"height":1805,"rx":1180,"fill":67,"stroke":68,"style":1181},"153.0","101.0",[1183,1807,1809],{"transform":1808},"translate(84.5,33.0) scale(1.000)",[1123,1810],{"d":1811,"fill":1189,"stroke":1812,"style":1191},"M5 9h14 M4 15h14 M10 4l-2 16 M16 4l-2 16","var(--text,#172033)",[19,1814,1818],{"x":1815,"y":1816,"style":1817},"96.5","79.5","font-size:13.5px;font-weight:700;fill:var(--text,#172033);text-anchor:middle","Count rows",[19,1820,1822],{"x":1815,"y":1821,"style":1241},"99.0","header included",[1824,1825],"circle",{"cx":1826,"cy":1827,"r":1828,"fill":1829,"stroke":1189,"style":1830},"36.0","32.0","11.0","#5b6780","stroke-width:0px",[19,1832,464],{"x":1826,"y":1833,"style":1834},"36.5","font-size:12px;font-weight:700;fill:#ffffff;text-anchor:middle",[158,1836],{"x1":1837,"y1":1838,"x2":1839,"y2":1838,"stroke":99,"style":1181},"178.0","66.5","200.0",[1208,1841],{"points":1842,"fill":1211},"204.0,66.5 195.0,71.5 195.0,61.5",[53,1844],{"x":1845,"y":63,"width":1804,"height":1805,"rx":1180,"fill":114,"stroke":115,"style":1181},"209.0",[1183,1847,1849],{"transform":1848},"translate(273.5,33.0) scale(1.000)",[1123,1850],{"d":1851,"fill":1189,"stroke":1293,"style":1191},"M4 4h16v16H4z M4 9h16 M4 14h16 M10 4v16",[19,1853,1855],{"x":1854,"y":1816,"style":1296},"285.5","Fits one sheet",[19,1857,1858],{"x":1854,"y":1821,"style":1241},"plain .xlsx",[1824,1860],{"cx":1861,"cy":1827,"r":1828,"fill":1862,"stroke":1189,"style":1830},"225.0","#0b6157",[19,1864,1865],{"x":1861,"y":1833,"style":1834},"2",[158,1867],{"x1":1868,"y1":1838,"x2":1869,"y2":1838,"stroke":99,"style":1181},"367.0","389.0",[1208,1871],{"points":1872,"fill":1211},"393.0,66.5 384.0,71.5 384.0,61.5",[53,1874],{"x":1875,"y":63,"width":1804,"height":1805,"rx":1180,"fill":98,"stroke":99,"style":1181},"398.0",[1183,1877,1879],{"transform":1878},"translate(462.5,33.0) scale(1.000)",[1123,1880],{"d":1233,"fill":1189,"stroke":1190,"style":1191},[19,1882,1884],{"x":1883,"y":1816,"style":1194},"474.5","Fits five sheets",[19,1886,1887],{"x":1883,"y":1821,"style":1241},"split workbook",[1824,1889],{"cx":1890,"cy":1827,"r":1828,"fill":1891,"stroke":1189,"style":1830},"414.0","#4338ca",[19,1893,865],{"x":1890,"y":1833,"style":1834},[158,1895],{"x1":1896,"y1":1838,"x2":1897,"y2":1838,"stroke":99,"style":1181},"556.0","578.0",[1208,1899],{"points":1900,"fill":1211},"582.0,66.5 573.0,71.5 573.0,61.5",[53,1902],{"x":1903,"y":63,"width":1804,"height":1805,"rx":1180,"fill":130,"stroke":131,"style":1181},"587.0",[1183,1905,1907],{"transform":1906},"translate(651.5,33.0) scale(1.000)",[1123,1908],{"d":1292,"fill":1189,"stroke":1264,"style":1191},[19,1910,1912],{"x":1911,"y":1816,"style":1267},"663.5","Larger",[19,1914,1915],{"x":1911,"y":1821,"style":1241},"Parquet + log",[1824,1917],{"cx":1918,"cy":1827,"r":1828,"fill":1919,"stroke":1189,"style":1830},"603.0","#8a5808",[19,1921,55],{"x":1918,"y":1833,"style":1834},[10,1923,1924],{},"Log which branch was taken. When a report switches from one sheet to a split workbook, the people who receive it should hear about it from you, not discover it.",[144,1926,1928],{"id":1927},"common-pitfalls","Common pitfalls",[1930,1931,1932,1940,1950,1960,1966],"ul",{},[1933,1934,1935,1939],"li",{},[1936,1937,1938],"strong",{},"Forgetting the header row."," Capacity under a header is 1,048,575 rows, not 1,048,576. Check with the full row count, as in Step 1.",[1933,1941,1942,1945,1946,1949],{},[1936,1943,1944],{},"Legacy .xls."," The old format holds 65,536 rows and 256 columns. Writing large data to ",[22,1947,1948],{},".xls"," is never the right choice.",[1933,1951,1952,1955,1956,1157],{},[1936,1953,1954],{},"Memory while writing."," Large exports can exhaust memory before they hit the row limit. Use xlsxwriter's constant-memory mode; see ",[28,1957,1959],{"href":1958},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Fwrite-a-million-rows-to-excel-with-xlsxwriter-constant-memory\u002F","Write a Million Rows to Excel with xlsxwriter",[1933,1961,1962,1965],{},[1936,1963,1964],{},"Blank rows between split sheets."," Readers who copy the sheets back together by hand miss rows at the boundaries. Tell them the split exists — name the sheets clearly and add a contents sheet listing each block's first and last key.",[1933,1967,1968,1971,1972,1975,1976,1979],{},[1936,1969,1970],{},"Index as an extra column."," The default ",[22,1973,1974],{},"index=True"," adds a column, which matters only near the column limit but always adds noise. Pass ",[22,1977,1978],{},"index=False"," unless the index is data.",[144,1981,1983],{"id":1982},"conclusion","Conclusion",[10,1985,1986],{},"\"This sheet is too large\" means the frame exceeds Excel's grid of 1,048,576 rows by 16,384 columns. Count the header when checking — a frame of exactly 1,048,576 rows loses its last row silently with xlsxwriter — then split long frames across sheets, melt or split wide ones, and deliver very large detail as CSV or Parquet with an Excel summary. Guard production exports so growth changes the format deliberately instead of crashing the job.",[144,1988,1990],{"id":1989},"frequently-asked-questions","Frequently asked questions",[10,1992,1993,1996],{},[1936,1994,1995],{},"What are Excel's size limits?","\nA worksheet has 1,048,576 rows and 16,384 columns (A to XFD). With a header row, at most 1,048,575 data rows fit under it.",[10,1998,1999,2002],{},[1936,2000,2001],{},"Why did my export lose its last row without an error?","\npandas compares the number of data rows with the sheet limit and forgets the header. A frame of exactly 1,048,576 rows passes the check; with the xlsxwriter engine the header plus all but the last row are written and the last row is dropped silently.",[10,2004,2005,2008],{},[1936,2006,2007],{},"Should I split the data across sheets or files?","\nSplit across sheets when one person needs all of it in one workbook. Split across files, or use CSV or Parquet, when the data feeds another system — Excel with over a million rows per sheet is slow to open and hard to use.",[10,2010,2011,2014],{},[1936,2012,2013],{},"Can I raise Excel's row limit?","\nNo. The grid size is fixed by the file format in every current version of Excel. Power Pivot and Power Query can hold larger tables in the data model, but a worksheet cannot show more than 1,048,576 rows.",[10,2016,2017,2020],{},[1936,2018,2019],{},"Does the limit apply to CSV files?","\nNo. A CSV file has no row limit, but Excel will only load the first 1,048,576 rows when opening it and warn that the rest were not loaded.",[144,2022,2024],{"id":2023},"related","Related",[1930,2026,2027,2033,2040,2047],{},[1933,2028,2029,2030,2032],{},"Up one level: ",[28,2031,31],{"href":30}," — every common error explained.",[1933,2034,2035,2039],{},[28,2036,2038],{"href":2037},"\u002Fadvanced-data-transformation-and-cleaning\u002Fworking-with-large-excel-files-in-python\u002F","Working with Large Excel Files in Python"," — reading and writing big workbooks.",[1933,2041,2042,2046],{},[28,2043,2045],{"href":2044},"\u002Fgetting-started-with-python-excel-automation\u002Fhandling-excel-file-formats-and-conversions\u002Fconvert-csv-files-to-excel-with-python\u002F","Convert CSV Files to Excel with Python"," — the same limit on the way in.",[1933,2048,2049,2053],{},[28,2050,2052],{"href":2051},"\u002Fadvanced-data-transformation-and-cleaning\u002Fworking-with-large-excel-files-in-python\u002Fwrite-large-dataframes-to-excel-with-write-only-mode\u002F","Write Large DataFrames to Excel with write_only Mode"," — memory-friendly writing with openpyxl.",[2055,2056,2057],"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 .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}html pre.shiki code .sa561, html code.shiki .sa561{--shiki-default:#E36209;--shiki-dark:#FFB757}html pre.shiki code .sSjpA, html code.shiki .sSjpA{--shiki-default:#005CC5;--shiki-dark:#FF9492}",{"title":20,"searchDepth":205,"depth":205,"links":2059},[2060,2061,2062,2063,2064,2065,2066,2067,2068,2069],{"id":146,"depth":205,"text":147},{"id":301,"depth":205,"text":302},{"id":526,"depth":205,"text":527},{"id":843,"depth":205,"text":844},{"id":1303,"depth":205,"text":1304},{"id":1562,"depth":205,"text":1563},{"id":1927,"depth":205,"text":1928},{"id":1982,"depth":205,"text":1983},{"id":1989,"depth":205,"text":1990},{"id":2023,"depth":205,"text":2024},"2026-09-23","pandas raises \"This sheet is too large! Your sheet size is … Max sheet size is 1048576, 16384\" when a DataFrame exceeds Excel's grid. Split rows across sheets, transpose or split wide frames, summarise, or choose another format — and avoid the off-by-one that silently drops a row.","md",[2074,2076,2078,2080,2082],{"q":1995,"a":2075},"A worksheet has 1,048,576 rows and 16,384 columns (A to XFD). With a header row, at most 1,048,575 data rows fit under it.",{"q":2001,"a":2077},"pandas compares the number of data rows with the sheet limit and forgets the header. A frame of exactly 1,048,576 rows passes the check; with the xlsxwriter engine the header plus all but the last row are written and the last row is dropped silently.",{"q":2007,"a":2079},"Split across sheets when one person needs all of it in one workbook. Split across files, or use CSV or Parquet, when the data feeds another system — Excel with over a million rows per sheet is slow to open and hard to use.",{"q":2013,"a":2081},"No. The grid size is fixed by the file format in every current version of Excel. Power Pivot and Power Query can hold larger tables in the data model, but a worksheet cannot show more than 1,048,576 rows.",{"q":2019,"a":2083},"No. A CSV file has no row limit, but Excel will only load the first 1,048,576 rows when opening it and warn that the rest were not loaded.","fix this sheet is too large when writing excel with pandas",null,{"breadcrumb":2087},[2088,2091,2094],{"name":2089,"item":2090},"Home","\u002F",{"name":2092,"item":2093},"Getting Started with Python Excel Automation","\u002Fgetting-started-with-python-excel-automation\u002F",{"name":31,"item":30},"\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-this-sheet-is-too-large-error",{"title":2097,"description":2098},"Fix ValueError: This sheet is too large! (pandas to_excel)","Fix pandas to_excel \"This sheet is too large! Max sheet size is 1048576, 16384\" — split long DataFrames across sheets, handle wide frames, account for the header row, and deliver big data as CSV or Parquet.","fix-this-sheet-is-too-large-error","getting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-this-sheet-is-too-large-error\u002Findex",[2102,2103,2104],"troubleshooting","large-files","pandas","how-to","zvCt-Xg34z_HrsGrpkAP5tnf3OozYogy2iOta1czSzo",[2108,2112],{"title":2109,"path":2110,"stem":2111,"children":-1},"Fix Text Truncated at 32,767 Characters in Excel Output","\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-text-truncated-at-32767-characters-in-excel","getting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-text-truncated-at-32767-characters-in-excel\u002Findex",{"title":2113,"path":2114,"stem":2115,"children":-1},"Fix \"Object of type Timestamp is not JSON serializable\" When Exporting Excel Data","\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-timestamp-is-not-json-serializable-when-exporting-excel-data","getting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-timestamp-is-not-json-serializable-when-exporting-excel-data\u002Findex",[2117,2119],{"path":2118,"title":2092},"\u002Fgetting-started-with-python-excel-automation",{"path":2120,"title":31},"\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors",[],[2123,2127,2130,2133,2136,2139],{"path":2124,"title":2125,"kind":2126},"\u002Fautomating-reporting-workflows\u002Ferror-handling-and-logging-in-excel-automation\u002Fhandle-permission-denied-when-writing-excel-in-python","Handle Permission Denied When Writing Excel in Python","fix",{"path":2128,"title":2129,"kind":2105},"\u002Fgetting-started-with-python-excel-automation\u002Fusing-openpyxl-for-excel-file-manipulation\u002Fwhat-openpyxl-loses-when-saving-an-existing-workbook","What openpyxl Loses When You Save an Existing Workbook",{"path":2131,"title":2132,"kind":2126},"\u002Fadvanced-data-transformation-and-cleaning\u002Fworking-with-dates-and-times-in-excel-data\u002Ffix-excel-serial-numbers-showing-instead-of-dates","Fix Excel Serial Numbers Showing Instead of Dates",{"path":2134,"title":2135,"kind":2105},"\u002Fadvanced-data-transformation-and-cleaning\u002Fworking-with-dates-and-times-in-excel-data\u002Fhandle-daylight-saving-time-in-excel-timestamps","Handle Daylight Saving Time in Excel Timestamps",{"path":2137,"title":2138,"kind":2105},"\u002Fautomating-reporting-workflows\u002Fautomating-excel-online-with-microsoft-graph\u002Fhandle-microsoft-graph-throttling-for-excel","Handle Microsoft Graph Throttling in Excel Automation",{"path":2140,"title":2141,"kind":2142},"\u002Fautomating-reporting-workflows\u002Ferror-handling-and-logging-in-excel-automation","Error Handling and Logging in Excel Automation","guide",1790972067503]