[{"data":1,"prerenderedAt":2322},["ShallowReactive",2],{"doc:\u002Fgetting-started-with-python-excel-automation\u002Fhandling-excel-file-formats-and-conversions\u002Fwrite-csv-files-that-open-correctly-in-excel":3,"surround:\u002Fgetting-started-with-python-excel-automation\u002Fhandling-excel-file-formats-and-conversions\u002Fwrite-csv-files-that-open-correctly-in-excel":2287,"ancestors:\u002Fgetting-started-with-python-excel-automation\u002Fhandling-excel-file-formats-and-conversions\u002Fwrite-csv-files-that-open-correctly-in-excel":2296,"children:\u002Fgetting-started-with-python-excel-automation\u002Fhandling-excel-file-formats-and-conversions\u002Fwrite-csv-files-that-open-correctly-in-excel":2301,"related:\u002Fgetting-started-with-python-excel-automation\u002Fhandling-excel-file-formats-and-conversions\u002Fwrite-csv-files-that-open-correctly-in-excel":2302},{"id":4,"title":5,"body":6,"dateModified":2253,"datePublished":2253,"description":2254,"extension":2255,"faq":2256,"keyword":2265,"kind":2266,"meta":2267,"navigation":119,"path":2276,"seo":2277,"slug":2280,"stem":2281,"topics":2282,"type":2285,"__hash__":2286},"docs\u002Fgetting-started-with-python-excel-automation\u002Fhandling-excel-file-formats-and-conversions\u002Fwrite-csv-files-that-open-correctly-in-excel\u002Findex.md","Write CSV Files That Open Correctly in Excel",{"type":7,"value":8,"toc":2239},"minimark",[9,44,49,74,77,302,306,392,414,622,626,634,708,726,733,849,862,1006,1010,1023,1145,1169,1173,1196,1263,1272,1276,1279,1313,1343,1968,1972,1986,2070,2083,2087,2138,2142,2151,2155,2174,2178,2184,2190,2196,2202,2206,2235],[10,11,12,13,17,18,21,22,25,26,29,30,33,34,37,38,43],"p",{},"Someone double-clicks the CSV your script produced and Excel shows ",[14,15,16],"code",{},"MÃ¼ller"," instead of ",[14,19,20],{},"Müller",", or puts each whole line into column A, or turns order number ",[14,23,24],{},"00412"," into ",[14,27,28],{},"412"," and a 16-digit card reference into ",[14,31,32],{},"4.53201E+15",". Nothing is wrong with the file in the strict sense — Python wrote valid CSV — but Excel opens CSV files by guessing, and its guesses depend on the user's regional settings. Because the recipient will not use the import wizard, the file has to be written so that the guesses come out right. This page covers the encoding, separator, number and date choices that make a CSV open cleanly by double-click, and the cases where the honest answer is to send an ",[14,35,36],{},".xlsx"," instead. It belongs to ",[39,40,42],"a",{"href":41},"\u002Fgetting-started-with-python-excel-automation\u002Fhandling-excel-file-formats-and-conversions\u002F","Handling Excel File Formats and Conversions",".",[45,46,48],"h2",{"id":47},"prerequisites","Prerequisites",[50,51,56],"pre",{"className":52,"code":53,"language":54,"meta":55,"style":55},"language-bash shiki shiki-themes github-light github-dark-high-contrast","pip install pandas\n","bash","",[14,57,58],{"__ignoreMap":55},[59,60,63,67,71],"span",{"class":61,"line":62},"line",1,[59,64,66],{"class":65},"sMTad","pip",[59,68,70],{"class":69},"srMev"," install",[59,72,73],{"class":69}," pandas\n",[10,75,76],{},"The examples use one small DataFrame with the usual troublemakers: accented names, an amount with decimals, an ID with leading zeros, a long reference number, a date, and a free-text note containing a comma, quotes and a line break.",[50,78,82],{"className":79,"code":80,"language":81,"meta":55,"style":55},"language-python shiki shiki-themes github-light github-dark-high-contrast","from pathlib import Path\nimport pandas as pd\n\ncustomers = pd.DataFrame({\n    \"CustomerID\": [\"00412\", \"00977\", \"01530\"],\n    \"Name\": [\"Müller GmbH\", \"Café Señor\", \"Øresund ApS\"],\n    \"Balance\": [1234.5, -88.25, 0.0],\n    \"Reference\": [\"4532015112830366\", \"4716123456789012\", \"6011000990139424\"],\n    \"Since\": pd.to_datetime([\"2019-03-04\", \"2021-11-30\", \"2024-01-15\"]),\n    \"Note\": ['Pays \"on time\", usually', \"Call before\\ndelivery\", \"\"],\n})\nprint(customers.dtypes)\n","python",[14,83,84,100,114,121,133,159,182,209,232,257,287,293],{"__ignoreMap":55},[59,85,86,90,94,97],{"class":61,"line":62},[59,87,89],{"class":88},"s-kum","from",[59,91,93],{"class":92},"skGVy"," pathlib ",[59,95,96],{"class":88},"import",[59,98,99],{"class":92}," Path\n",[59,101,103,105,108,111],{"class":61,"line":102},2,[59,104,96],{"class":88},[59,106,107],{"class":92}," pandas ",[59,109,110],{"class":88},"as",[59,112,113],{"class":92}," pd\n",[59,115,117],{"class":61,"line":116},3,[59,118,120],{"emptyLinePlaceholder":119},true,"\n",[59,122,124,127,130],{"class":61,"line":123},4,[59,125,126],{"class":92},"customers ",[59,128,129],{"class":88},"=",[59,131,132],{"class":92}," pd.DataFrame({\n",[59,134,136,139,142,145,148,151,153,156],{"class":61,"line":135},5,[59,137,138],{"class":69},"    \"CustomerID\"",[59,140,141],{"class":92},": [",[59,143,144],{"class":69},"\"00412\"",[59,146,147],{"class":92},", ",[59,149,150],{"class":69},"\"00977\"",[59,152,147],{"class":92},[59,154,155],{"class":69},"\"01530\"",[59,157,158],{"class":92},"],\n",[59,160,162,165,167,170,172,175,177,180],{"class":61,"line":161},6,[59,163,164],{"class":69},"    \"Name\"",[59,166,141],{"class":92},[59,168,169],{"class":69},"\"Müller GmbH\"",[59,171,147],{"class":92},[59,173,174],{"class":69},"\"Café Señor\"",[59,176,147],{"class":92},[59,178,179],{"class":69},"\"Øresund ApS\"",[59,181,158],{"class":92},[59,183,185,188,190,194,196,199,202,204,207],{"class":61,"line":184},7,[59,186,187],{"class":69},"    \"Balance\"",[59,189,141],{"class":92},[59,191,193],{"class":192},"sP0c6","1234.5",[59,195,147],{"class":92},[59,197,198],{"class":88},"-",[59,200,201],{"class":192},"88.25",[59,203,147],{"class":92},[59,205,206],{"class":192},"0.0",[59,208,158],{"class":92},[59,210,212,215,217,220,222,225,227,230],{"class":61,"line":211},8,[59,213,214],{"class":69},"    \"Reference\"",[59,216,141],{"class":92},[59,218,219],{"class":69},"\"4532015112830366\"",[59,221,147],{"class":92},[59,223,224],{"class":69},"\"4716123456789012\"",[59,226,147],{"class":92},[59,228,229],{"class":69},"\"6011000990139424\"",[59,231,158],{"class":92},[59,233,235,238,241,244,246,249,251,254],{"class":61,"line":234},9,[59,236,237],{"class":69},"    \"Since\"",[59,239,240],{"class":92},": pd.to_datetime([",[59,242,243],{"class":69},"\"2019-03-04\"",[59,245,147],{"class":92},[59,247,248],{"class":69},"\"2021-11-30\"",[59,250,147],{"class":92},[59,252,253],{"class":69},"\"2024-01-15\"",[59,255,256],{"class":92},"]),\n",[59,258,260,263,265,268,270,273,277,280,282,285],{"class":61,"line":259},10,[59,261,262],{"class":69},"    \"Note\"",[59,264,141],{"class":92},[59,266,267],{"class":69},"'Pays \"on time\", usually'",[59,269,147],{"class":92},[59,271,272],{"class":69},"\"Call before",[59,274,276],{"class":275},"sSjpA","\\n",[59,278,279],{"class":69},"delivery\"",[59,281,147],{"class":92},[59,283,284],{"class":69},"\"\"",[59,286,158],{"class":92},[59,288,290],{"class":61,"line":289},11,[59,291,292],{"class":92},"})\n",[59,294,296,299],{"class":61,"line":295},12,[59,297,298],{"class":192},"print",[59,300,301],{"class":92},"(customers.dtypes)\n",[45,303,305],{"id":304},"step-1-write-utf-8-with-a-byte-order-mark","Step 1 — Write UTF-8 with a byte order mark",[50,307,309],{"className":79,"code":308,"language":81,"meta":55,"style":55},"customers.to_csv(\"plain.csv\", index=False)\ncustomers.to_csv(\"excel.csv\", index=False, encoding=\"utf-8-sig\")\nprint(Path(\"plain.csv\").read_bytes()[:12])\nprint(Path(\"excel.csv\").read_bytes()[:12])\n",[14,310,311,333,360,378],{"__ignoreMap":55},[59,312,313,316,319,321,325,327,330],{"class":61,"line":62},[59,314,315],{"class":92},"customers.to_csv(",[59,317,318],{"class":69},"\"plain.csv\"",[59,320,147],{"class":92},[59,322,324],{"class":323},"sa561","index",[59,326,129],{"class":88},[59,328,329],{"class":192},"False",[59,331,332],{"class":92},")\n",[59,334,335,337,340,342,344,346,348,350,353,355,358],{"class":61,"line":102},[59,336,315],{"class":92},[59,338,339],{"class":69},"\"excel.csv\"",[59,341,147],{"class":92},[59,343,324],{"class":323},[59,345,129],{"class":88},[59,347,329],{"class":192},[59,349,147],{"class":92},[59,351,352],{"class":323},"encoding",[59,354,129],{"class":88},[59,356,357],{"class":69},"\"utf-8-sig\"",[59,359,332],{"class":92},[59,361,362,364,367,369,372,375],{"class":61,"line":116},[59,363,298],{"class":192},[59,365,366],{"class":92},"(Path(",[59,368,318],{"class":69},[59,370,371],{"class":92},").read_bytes()[:",[59,373,374],{"class":192},"12",[59,376,377],{"class":92},"])\n",[59,379,380,382,384,386,388,390],{"class":61,"line":123},[59,381,298],{"class":192},[59,383,366],{"class":92},[59,385,339],{"class":69},[59,387,371],{"class":92},[59,389,374],{"class":192},[59,391,377],{"class":92},[10,393,394,395,398,399,402,403,25,406,409,410,413],{},"The only difference is the first three bytes: ",[14,396,397],{},"utf-8-sig"," writes ",[14,400,401],{},"EF BB BF",", the UTF-8 byte order mark (BOM). When Excel opens a CSV by double-click it looks for that mark; without it, Windows Excel decodes the file with the legacy code page of the user's locale, which turns every ",[14,404,405],{},"ü",[14,407,408],{},"Ã¼",". Python's own ",[14,411,412],{},"pd.read_csv"," and most other tools ignore or strip the mark, so writing it costs nothing. This is the single most important setting in this page.",[415,416,424,425,424,429,424,433,424,441,424,450,424,454,424,461,424,465,424,469,424,473,424,478,424,483,424,487,424,489,424,492,424,495,424,499,424,501,424,504,424,508,424,512,424,515,424,519,424,521,424,524,424,526,424,529,424,532,424,535,424,538,424,542,424,545,424,547,424,550,424,552,424,554,424,556,424,558,424,560,424,562,424,564,424,566,424,570,424,574,424,576,424,578,424,580,424,582,424,584,424,587,424,593,424,597,424,603,424,608,424,616],"svg",{"viewBox":417,"role":418,"ariaLabelledBy":419,"xmlns":422,"style":423},"16 0 728 164","img",[420,421],"csv-bom-t","csv-bom-d","http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg","width:100%;max-width:728px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif","\n  ",[426,427,428],"title",{"id":420},"Three bytes decide how Excel decodes the file",[430,431,432],"desc",{"id":421},"The same CSV opened in Excel. Without a byte order mark, Excel decodes it with the local code page and Müller GmbH appears as MÃ¼ller GmbH. With the UTF-8 byte order mark written by encoding utf-8-sig, the name appears correctly.",[434,435],"rect",{"x":436,"y":437,"width":438,"height":439,"fill":440},"16","0","728","164","#ffffff",[434,442],{"x":443,"y":444,"width":445,"height":446,"rx":437,"fill":447,"stroke":448,"style":449},"32.4","40.0","32.0","24.0","#e7ebef","var(--line,#cdd5e6)","stroke-width:1px",[434,451],{"x":452,"y":444,"width":453,"height":446,"rx":437,"fill":447,"stroke":448,"style":449},"64.4","91.2",[455,456,460],"text",{"x":457,"y":458,"style":459},"110.0","57.0","font-size:11px;font-weight:600;fill:var(--muted,#5b6780);text-anchor:middle","A",[434,462],{"x":463,"y":444,"width":464,"height":446,"rx":437,"fill":447,"stroke":448,"style":449},"155.7","104.3",[455,466,468],{"x":467,"y":458,"style":459},"207.8","B",[434,470],{"x":443,"y":471,"width":445,"height":472,"rx":437,"fill":447,"stroke":448,"style":449},"64.0","28.0",[455,474,477],{"x":475,"y":476,"style":459},"48.4","83.0","1",[434,479],{"x":452,"y":471,"width":453,"height":472,"rx":437,"fill":480,"stroke":481,"style":482},"#f0f4ff","var(--brand,#5b5cf0)","stroke-width:1.5px",[455,484,486],{"x":457,"y":476,"style":485},"font-size:11px;font-weight:700;fill:var(--brand-strong,#4338ca);text-anchor:middle","CustomerID",[434,488],{"x":463,"y":471,"width":464,"height":472,"rx":437,"fill":480,"stroke":481,"style":482},[455,490,491],{"x":467,"y":476,"style":485},"Name",[434,493],{"x":443,"y":494,"width":445,"height":472,"rx":437,"fill":447,"stroke":448,"style":449},"92.0",[455,496,498],{"x":475,"y":497,"style":459},"111.0","2",[434,500],{"x":452,"y":494,"width":453,"height":472,"rx":437,"fill":440,"stroke":448,"style":449},[455,502,28],{"x":457,"y":497,"style":503},"font-size:11px;font-weight:400;fill:var(--text,#172033);text-anchor:middle",[434,505],{"x":463,"y":494,"width":464,"height":472,"rx":437,"fill":506,"stroke":507,"style":482},"#fce9e9","var(--danger,#dc2626)",[455,509,511],{"x":467,"y":497,"style":510},"font-size:11px;font-weight:700;fill:var(--accent-ink,#be185d);text-anchor:middle","MÃ¼ller GmbH",[434,513],{"x":443,"y":514,"width":445,"height":472,"rx":437,"fill":447,"stroke":448,"style":449},"120.0",[455,516,518],{"x":475,"y":517,"style":459},"139.0","3",[434,520],{"x":452,"y":514,"width":453,"height":472,"rx":437,"fill":440,"stroke":448,"style":449},[455,522,523],{"x":457,"y":517,"style":503},"977",[434,525],{"x":463,"y":514,"width":464,"height":472,"rx":437,"fill":506,"stroke":507,"style":482},[455,527,528],{"x":467,"y":517,"style":510},"CafÃ© SeÃ±or",[434,530],{"x":531,"y":444,"width":445,"height":446,"rx":437,"fill":447,"stroke":448,"style":449},"506.7",[434,533],{"x":534,"y":444,"width":453,"height":446,"rx":437,"fill":447,"stroke":448,"style":449},"538.7",[455,536,460],{"x":537,"y":458,"style":459},"584.3",[434,539],{"x":540,"y":444,"width":541,"height":446,"rx":437,"fill":447,"stroke":448,"style":449},"629.9","97.7",[455,543,468],{"x":544,"y":458,"style":459},"678.7",[434,546],{"x":531,"y":471,"width":445,"height":472,"rx":437,"fill":447,"stroke":448,"style":449},[455,548,477],{"x":549,"y":476,"style":459},"522.7",[434,551],{"x":534,"y":471,"width":453,"height":472,"rx":437,"fill":480,"stroke":481,"style":482},[455,553,486],{"x":537,"y":476,"style":485},[434,555],{"x":540,"y":471,"width":541,"height":472,"rx":437,"fill":480,"stroke":481,"style":482},[455,557,491],{"x":544,"y":476,"style":485},[434,559],{"x":531,"y":494,"width":445,"height":472,"rx":437,"fill":447,"stroke":448,"style":449},[455,561,498],{"x":549,"y":497,"style":459},[434,563],{"x":534,"y":494,"width":453,"height":472,"rx":437,"fill":440,"stroke":448,"style":449},[455,565,28],{"x":537,"y":497,"style":503},[434,567],{"x":540,"y":494,"width":541,"height":472,"rx":437,"fill":568,"stroke":569,"style":482},"#d9f4f1","var(--teal,#0f9488)",[455,571,573],{"x":544,"y":497,"style":572},"font-size:11px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:middle","Müller GmbH",[434,575],{"x":531,"y":514,"width":445,"height":472,"rx":437,"fill":447,"stroke":448,"style":449},[455,577,518],{"x":549,"y":517,"style":459},[434,579],{"x":534,"y":514,"width":453,"height":472,"rx":437,"fill":440,"stroke":448,"style":449},[455,581,523],{"x":537,"y":517,"style":503},[434,583],{"x":540,"y":514,"width":541,"height":472,"rx":437,"fill":568,"stroke":569,"style":482},[455,585,586],{"x":544,"y":517,"style":572},"Café Señor",[455,588,592],{"x":589,"y":590,"style":591},"146.2","29.0","font-size:12.5px;font-weight:700;fill:var(--muted,#5b6780);text-anchor:middle","no BOM",[455,594,596],{"x":595,"y":590,"style":591},"617.1","with BOM",[61,598],{"x1":599,"y1":600,"x2":601,"y2":600,"stroke":481,"style":602},"270.0","94.0","492.7","stroke-width:2px",[604,605],"polygon",{"points":606,"fill":607},"496.7,94.0 487.7,99.0 487.7,89.0","#5b5cf0",[434,609],{"x":610,"y":611,"width":612,"height":613,"rx":614,"fill":440,"stroke":448,"style":615},"300.6","61.0","165.4","22.0","11","stroke-width:1.2px",[455,617,621],{"x":618,"y":619,"style":620},"383.3","76.0","font-size:11.5px;font-weight:400;fill:var(--brand-strong,#4338ca);text-anchor:middle;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace","encoding=\"utf-8-sig\"",[45,623,625],{"id":624},"step-2-use-the-separator-the-readers-excel-expects","Step 2 — Use the separator the reader's Excel expects",[10,627,628,629,633],{},"Excel splits a CSV on the ",[630,631,632],"em",{},"list separator"," from the operating system's regional settings. In the United States and the UK that is a comma. In most of continental Europe, where the comma is the decimal mark, it is a semicolon — and a comma-separated file opens with every row crammed into column A. If you know the audience, write for it:",[50,635,637],{"className":79,"code":636,"language":81,"meta":55,"style":55},"customers.to_csv(\"excel_de.csv\", index=False, encoding=\"utf-8-sig\", sep=\";\", decimal=\",\")\nprint(Path(\"excel_de.csv\").read_text(encoding=\"utf-8-sig\").splitlines()[1])\n",[14,638,639,684],{"__ignoreMap":55},[59,640,641,643,646,648,650,652,654,656,658,660,662,664,667,669,672,674,677,679,682],{"class":61,"line":62},[59,642,315],{"class":92},[59,644,645],{"class":69},"\"excel_de.csv\"",[59,647,147],{"class":92},[59,649,324],{"class":323},[59,651,129],{"class":88},[59,653,329],{"class":192},[59,655,147],{"class":92},[59,657,352],{"class":323},[59,659,129],{"class":88},[59,661,357],{"class":69},[59,663,147],{"class":92},[59,665,666],{"class":323},"sep",[59,668,129],{"class":88},[59,670,671],{"class":69},"\";\"",[59,673,147],{"class":92},[59,675,676],{"class":323},"decimal",[59,678,129],{"class":88},[59,680,681],{"class":69},"\",\"",[59,683,332],{"class":92},[59,685,686,688,690,692,695,697,699,701,704,706],{"class":61,"line":102},[59,687,298],{"class":192},[59,689,366],{"class":92},[59,691,645],{"class":69},[59,693,694],{"class":92},").read_text(",[59,696,352],{"class":323},[59,698,129],{"class":88},[59,700,357],{"class":69},[59,702,703],{"class":92},").splitlines()[",[59,705,477],{"class":192},[59,707,377],{"class":92},[10,709,710,713,714,398,717,17,720,722,723,725],{},[14,711,712],{},"sep=\";\""," changes the separator and ",[14,715,716],{},"decimal=\",\"",[14,718,719],{},"1234,5",[14,721,193],{},", so German, French or Dutch Excel reads the balance as a number. Mixing them up is worse than either: a semicolon file with decimal points opens in German Excel with ",[14,724,193],{}," as text, or worse, as a date.",[10,727,728,729,732],{},"When one file must serve both kinds of user, Excel honours a first line of the form ",[14,730,731],{},"sep=;",", which overrides the regional setting:",[50,734,736],{"className":79,"code":735,"language":81,"meta":55,"style":55},"with open(\"excel_any.csv\", \"w\", encoding=\"utf-8-sig\", newline=\"\") as fh:\n    fh.write(\"sep=;\\n\")\n    customers.to_csv(fh, index=False, sep=\";\", decimal=\",\")\nprint(Path(\"excel_any.csv\").read_text(encoding=\"utf-8-sig\").splitlines()[:2])\n",[14,737,738,782,797,826],{"__ignoreMap":55},[59,739,740,743,746,749,752,754,757,759,761,763,765,767,770,772,774,777,779],{"class":61,"line":62},[59,741,742],{"class":88},"with",[59,744,745],{"class":192}," open",[59,747,748],{"class":92},"(",[59,750,751],{"class":69},"\"excel_any.csv\"",[59,753,147],{"class":92},[59,755,756],{"class":69},"\"w\"",[59,758,147],{"class":92},[59,760,352],{"class":323},[59,762,129],{"class":88},[59,764,357],{"class":69},[59,766,147],{"class":92},[59,768,769],{"class":323},"newline",[59,771,129],{"class":88},[59,773,284],{"class":69},[59,775,776],{"class":92},") ",[59,778,110],{"class":88},[59,780,781],{"class":92}," fh:\n",[59,783,784,787,790,792,795],{"class":61,"line":102},[59,785,786],{"class":92},"    fh.write(",[59,788,789],{"class":69},"\"sep=;",[59,791,276],{"class":275},[59,793,794],{"class":69},"\"",[59,796,332],{"class":92},[59,798,799,802,804,806,808,810,812,814,816,818,820,822,824],{"class":61,"line":116},[59,800,801],{"class":92},"    customers.to_csv(fh, ",[59,803,324],{"class":323},[59,805,129],{"class":88},[59,807,329],{"class":192},[59,809,147],{"class":92},[59,811,666],{"class":323},[59,813,129],{"class":88},[59,815,671],{"class":69},[59,817,147],{"class":92},[59,819,676],{"class":323},[59,821,129],{"class":88},[59,823,681],{"class":69},[59,825,332],{"class":92},[59,827,828,830,832,834,836,838,840,842,845,847],{"class":61,"line":123},[59,829,298],{"class":192},[59,831,366],{"class":92},[59,833,751],{"class":69},[59,835,694],{"class":92},[59,837,352],{"class":323},[59,839,129],{"class":88},[59,841,357],{"class":69},[59,843,844],{"class":92},").splitlines()[:",[59,846,498],{"class":192},[59,848,377],{"class":92},[10,850,851,852,854,855,857,858,861],{},"Use the hint with care: it is an Excel convention, not part of the CSV format. Other programs, including ",[14,853,412],{},", see ",[14,856,731],{}," as the header row unless told to skip it (",[14,859,860],{},"skiprows=1","), so only add it to files meant purely for people.",[415,863,424,869,424,872,424,875,424,880,424,886,424,897,424,902,424,906,424,910,424,913,424,916,424,923,424,928,424,934,424,941,424,946,424,951,424,953,424,956,424,960,424,963,424,966,424,971,424,973,424,975,424,977,424,980,424,984,424,987,424,992,424,999,424,1003],{"viewBox":864,"role":418,"ariaLabelledBy":865,"xmlns":422,"style":868},"4 0 752 272",[866,867],"csv-sep-t","csv-sep-d","width:100%;max-width:752px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif",[426,870,871],{"id":866},"Choosing the separator and decimal mark",[430,873,874],{"id":867},"For readers whose Excel uses comma as the list separator, write comma-separated values with a decimal point. For readers in locales that use comma as the decimal mark, write semicolon-separated values with decimal comma. For a mixed audience, either add the sep= hint line or send an xlsx file.",[434,876],{"x":877,"y":437,"width":878,"height":879,"fill":440},"4","752","272",[434,881],{"x":882,"y":883,"width":884,"height":885,"rx":374,"fill":480,"stroke":481,"style":602},"240.0","16.0","280.0","75.5",[887,888,890],"g",{"transform":889},"translate(368.0,29.0) scale(1.000)",[891,892],"path",{"d":893,"fill":894,"stroke":895,"style":896},"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",[455,898,901],{"x":899,"y":885,"style":900},"380.0","font-size:13.5px;font-weight:700;fill:var(--brand-strong,#4338ca);text-anchor:middle","Where will the file be opened?",[61,903],{"x1":899,"y1":904,"x2":899,"y2":905,"stroke":481,"style":602},"91.5","111.5",[61,907],{"x1":908,"y1":905,"x2":909,"y2":905,"stroke":481,"style":602},"134.7","625.3",[61,911],{"x1":908,"y1":905,"x2":908,"y2":912,"stroke":481,"style":602},"157.5",[604,914],{"points":915,"fill":607},"134.7,161.5 129.7,152.5 139.7,152.5",[434,917],{"x":918,"y":919,"width":920,"height":921,"rx":922,"fill":440,"stroke":448,"style":615},"77.9","121.5","113.5","21.0","10",[455,924,927],{"x":908,"y":925,"style":926},"136.0","font-size:11.5px;font-weight:700;fill:var(--muted,#5b6780);text-anchor:middle","US \u002F UK settings",[434,929],{"x":930,"y":931,"width":932,"height":933,"rx":374,"fill":568,"stroke":569,"style":602},"20.0","163.5","229.3","93.0",[887,935,937],{"transform":936},"translate(122.7,176.5) scale(1.000)",[891,938],{"d":939,"fill":894,"stroke":940,"style":896},"M5 12.5l4.5 4.5L19 7","var(--teal-ink,#0b6157)",[455,942,945],{"x":908,"y":943,"style":944},"223.0","font-size:13.5px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:middle","sep=\",\"",[455,947,950],{"x":908,"y":948,"style":949},"242.5","font-size:11.5px;font-weight:400;fill:var(--text,#172033);text-anchor:middle","decimal point",[61,952],{"x1":899,"y1":905,"x2":899,"y2":912,"stroke":481,"style":602},[604,954],{"points":955,"fill":607},"380.0,161.5 375.0,152.5 385.0,152.5",[434,957],{"x":958,"y":919,"width":959,"height":921,"rx":922,"fill":440,"stroke":448,"style":615},"315.2","129.5",[455,961,962],{"x":899,"y":925,"style":926},"continental Europe",[434,964],{"x":965,"y":931,"width":932,"height":933,"rx":374,"fill":568,"stroke":569,"style":602},"265.3",[887,967,969],{"transform":968},"translate(368.0,176.5) scale(1.000)",[891,970],{"d":939,"fill":894,"stroke":940,"style":896},[455,972,712],{"x":899,"y":943,"style":944},[455,974,716],{"x":899,"y":948,"style":949},[61,976],{"x1":909,"y1":905,"x2":909,"y2":912,"stroke":481,"style":602},[604,978],{"points":979,"fill":607},"625.3,161.5 620.3,152.5 630.3,152.5",[434,981],{"x":982,"y":919,"width":983,"height":921,"rx":922,"fill":440,"stroke":448,"style":615},"602.9","45.0",[455,985,986],{"x":909,"y":925,"style":926},"both",[434,988],{"x":989,"y":931,"width":932,"height":933,"rx":374,"fill":990,"stroke":991,"style":602},"510.7","#fdefd8","var(--gold,#b4740a)",[887,993,995],{"transform":994},"translate(613.3,176.5) scale(1.000)",[891,996],{"d":997,"fill":894,"stroke":998,"style":896},"M12 3.5l9.5 17h-19z M12 10v5 M12 17.8v.4","var(--gold-ink,#7a4e06)",[455,1000,1002],{"x":909,"y":943,"style":1001},"font-size:13.5px;font-weight:700;fill:var(--gold-ink,#7a4e06);text-anchor:middle","sep= hint line",[455,1004,1005],{"x":909,"y":948,"style":949},"Excel-only; or send xlsx",[45,1007,1009],{"id":1008},"step-3-keep-leading-zeros-and-long-numbers","Step 3 — Keep leading zeros and long numbers",[10,1011,1012,1013,1015,1016,1018,1019,1022],{},"Excel converts anything that looks like a number. ",[14,1014,24],{}," becomes ",[14,1017,28],{},", and a 16-digit reference becomes a floating-point number shown as ",[14,1020,1021],{},"4.53202E+15"," — and because Excel keeps only 15 significant digits, the last digit is replaced by a zero the moment the file is saved again. CSV has no way to mark a field as text, so the only CSV-level fix is to make the value not look like a number. The common trick is to write it as a formula that returns text:",[50,1024,1026],{"className":79,"code":1025,"language":81,"meta":55,"style":55},"protected = customers.assign(\n    CustomerID='=\"' + customers[\"CustomerID\"] + '\"',\n    Reference='=\"' + customers[\"Reference\"] + '\"',\n)\nprotected.to_csv(\"excel_ids.csv\", index=False, encoding=\"utf-8-sig\")\nprint(Path(\"excel_ids.csv\").read_text(encoding=\"utf-8-sig\").splitlines()[1])\n",[14,1027,1028,1038,1069,1093,1097,1123],{"__ignoreMap":55},[59,1029,1030,1033,1035],{"class":61,"line":62},[59,1031,1032],{"class":92},"protected ",[59,1034,129],{"class":88},[59,1036,1037],{"class":92}," customers.assign(\n",[59,1039,1040,1043,1045,1048,1051,1054,1057,1060,1063,1066],{"class":61,"line":102},[59,1041,1042],{"class":323},"    CustomerID",[59,1044,129],{"class":88},[59,1046,1047],{"class":69},"'=\"'",[59,1049,1050],{"class":88}," +",[59,1052,1053],{"class":92}," customers[",[59,1055,1056],{"class":69},"\"CustomerID\"",[59,1058,1059],{"class":92},"] ",[59,1061,1062],{"class":88},"+",[59,1064,1065],{"class":69}," '\"'",[59,1067,1068],{"class":92},",\n",[59,1070,1071,1074,1076,1078,1080,1082,1085,1087,1089,1091],{"class":61,"line":116},[59,1072,1073],{"class":323},"    Reference",[59,1075,129],{"class":88},[59,1077,1047],{"class":69},[59,1079,1050],{"class":88},[59,1081,1053],{"class":92},[59,1083,1084],{"class":69},"\"Reference\"",[59,1086,1059],{"class":92},[59,1088,1062],{"class":88},[59,1090,1065],{"class":69},[59,1092,1068],{"class":92},[59,1094,1095],{"class":61,"line":123},[59,1096,332],{"class":92},[59,1098,1099,1102,1105,1107,1109,1111,1113,1115,1117,1119,1121],{"class":61,"line":135},[59,1100,1101],{"class":92},"protected.to_csv(",[59,1103,1104],{"class":69},"\"excel_ids.csv\"",[59,1106,147],{"class":92},[59,1108,324],{"class":323},[59,1110,129],{"class":88},[59,1112,329],{"class":192},[59,1114,147],{"class":92},[59,1116,352],{"class":323},[59,1118,129],{"class":88},[59,1120,357],{"class":69},[59,1122,332],{"class":92},[59,1124,1125,1127,1129,1131,1133,1135,1137,1139,1141,1143],{"class":61,"line":161},[59,1126,298],{"class":192},[59,1128,366],{"class":92},[59,1130,1104],{"class":69},[59,1132,694],{"class":92},[59,1134,352],{"class":323},[59,1136,129],{"class":88},[59,1138,357],{"class":69},[59,1140,703],{"class":92},[59,1142,477],{"class":192},[59,1144,377],{"class":92},[10,1146,1147,1148,1151,1152,1155,1156,1158,1159,1161,1162,1164,1165,43],{},"Each ID is written as ",[14,1149,1150],{},"\"=\"\"00412\"\"\""," — CSV quoting around ",[14,1153,1154],{},"=\"00412\""," — which Excel evaluates as a formula producing the text ",[14,1157,24],{},". It works by double-click, but it pollutes the file for every other consumer, which now receives ",[14,1160,1154],{}," as the value. Use it only for files that exist to be opened in Excel; for anything else, IDs with leading zeros are a strong reason to send an ",[14,1163,36],{},", where the cell can simply be text — see ",[39,1166,1168],{"href":1167},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fapplying-number-and-date-formats-in-excel\u002Fformat-zip-codes-and-ids-with-leading-zeros\u002F","Format ZIP Codes and IDs with Leading Zeros",[45,1170,1172],{"id":1171},"step-4-write-dates-excel-will-recognise","Step 4 — Write dates Excel will recognise",[10,1174,1175,1176,1179,1180,1183,1184,1187,1188,1191,1192,1195],{},"A ",[14,1177,1178],{},"datetime64"," column is written as ",[14,1181,1182],{},"2019-03-04"," by default (or with ",[14,1185,1186],{}," 00:00:00"," if any value has a time). ISO ",[14,1189,1190],{},"yyyy-mm-dd"," is the safest choice: Excel recognises it as a date in every locale. Writing local formats such as ",[14,1193,1194],{},"04\u002F03\u002F2019"," invites the classic day–month swap, where an American Excel reads 4 March as April 3rd:",[50,1197,1199],{"className":79,"code":1198,"language":81,"meta":55,"style":55},"customers.to_csv(\"excel_dates.csv\", index=False, encoding=\"utf-8-sig\", date_format=\"%Y-%m-%d\")\nprint(Path(\"excel_dates.csv\").read_text(encoding=\"utf-8-sig\").splitlines()[1])\n",[14,1200,1201,1241],{"__ignoreMap":55},[59,1202,1203,1205,1208,1210,1212,1214,1216,1218,1220,1222,1224,1226,1229,1231,1234,1237,1239],{"class":61,"line":62},[59,1204,315],{"class":92},[59,1206,1207],{"class":69},"\"excel_dates.csv\"",[59,1209,147],{"class":92},[59,1211,324],{"class":323},[59,1213,129],{"class":88},[59,1215,329],{"class":192},[59,1217,147],{"class":92},[59,1219,352],{"class":323},[59,1221,129],{"class":88},[59,1223,357],{"class":69},[59,1225,147],{"class":92},[59,1227,1228],{"class":323},"date_format",[59,1230,129],{"class":88},[59,1232,1233],{"class":69},"\"%Y-%m-",[59,1235,1236],{"class":275},"%d",[59,1238,794],{"class":69},[59,1240,332],{"class":92},[59,1242,1243,1245,1247,1249,1251,1253,1255,1257,1259,1261],{"class":61,"line":102},[59,1244,298],{"class":192},[59,1246,366],{"class":92},[59,1248,1207],{"class":69},[59,1250,694],{"class":92},[59,1252,352],{"class":323},[59,1254,129],{"class":88},[59,1256,357],{"class":69},[59,1258,703],{"class":92},[59,1260,477],{"class":192},[59,1262,377],{"class":92},[10,1264,1265,1267,1268,1271],{},[14,1266,1228],{}," controls every datetime column in one place. If times matter, ",[14,1269,1270],{},"\"%Y-%m-%d %H:%M\""," is also recognised. Time zones should be converted and removed before writing; Excel has no notion of them.",[45,1273,1275],{"id":1274},"step-5-quote-text-with-commas-quotes-and-line-breaks","Step 5 — Quote text with commas, quotes and line breaks",[10,1277,1278],{},"pandas quotes fields that contain the separator, a quote character or a line break, and doubles embedded quotes, which is exactly what Excel expects:",[50,1280,1282],{"className":79,"code":1281,"language":81,"meta":55,"style":55},"line = Path(\"excel.csv\").read_text(encoding=\"utf-8-sig\")\nprint(line)\n",[14,1283,1284,1306],{"__ignoreMap":55},[59,1285,1286,1289,1291,1294,1296,1298,1300,1302,1304],{"class":61,"line":62},[59,1287,1288],{"class":92},"line ",[59,1290,129],{"class":88},[59,1292,1293],{"class":92}," Path(",[59,1295,339],{"class":69},[59,1297,694],{"class":92},[59,1299,352],{"class":323},[59,1301,129],{"class":88},[59,1303,357],{"class":69},[59,1305,332],{"class":92},[59,1307,1308,1310],{"class":61,"line":102},[59,1309,298],{"class":192},[59,1311,1312],{"class":92},"(line)\n",[10,1314,1315,1316,1319,1320,1323,1324,1327,1328,147,1330,147,1332,1334,1335,1338,1339,43],{},"The note ",[14,1317,1318],{},"Pays \"on time\", usually"," is written as ",[14,1321,1322],{},"\"Pays \"\"on time\"\", usually\"",", and the note with a line break is wrapped in quotes so the break stays inside one cell. Do not \"help\" by stripping quotes or setting ",[14,1325,1326],{},"quoting=csv.QUOTE_NONE"," — that is what produces rows split across lines and shifted columns. Text that starts with ",[14,1329,129],{},[14,1331,1062],{},[14,1333,198],{}," or ",[14,1336,1337],{},"@"," is a different danger: Excel executes it as a formula, which is how formula injection works; neutralise it as described in ",[39,1340,1342],{"href":1341},"\u002Fautomating-reporting-workflows\u002Ferror-handling-and-logging-in-excel-automation\u002Fprevent-formula-injection-in-excel-exports\u002F","Prevent Formula Injection in Excel Exports",[415,1344,424,1350,424,1353,424,1356,424,1360,424,1363,424,1367,424,1373,424,1377,424,1382,424,1384,424,1388,424,1391,424,1399,424,1402,424,1406,424,1409,424,1413,424,1416,424,1420,424,1423,424,1427,424,1430,424,1435,424,1438,424,1441,424,1444,424,1447,424,1450,424,1453,424,1456,424,1460,424,1463,424,1467,424,1470,424,1474,424,1477,424,1482,424,1485,424,1489,424,1492,424,1497,424,1500,424,1504,424,1507,424,1510,424,1513,424,1516,424,1519,424,1522,424,1525,424,1529,424,1531,424,1533,424,1535,424,1538,424,1540,424,1542,424,1544,424,1546,424,1548,424,1550,424,1552,424,1555,424,1557,424,1560,424,1562,424,1564,424,1566,424,1568,424,1570,424,1572,424,1574,424,1577,424,1579,424,1581,424,1583,424,1585,424,1587,424,1590,424,1592,424,1594,424,1596,424,1599,424,1601,424,1603,424,1605,424,1608,424,1610,424,1612,424,1614,424,1619,424,1622,424,1625,424,1628,424,1632,424,1635,424,1639,424,1641,424,1644,424,1646,424,1648,424,1650,424,1652,424,1654,424,1656,424,1658,424,1661,424,1663,424,1665,424,1667,424,1670,424,1672,424,1674,424,1676,424,1678,424,1680,424,1683,424,1685,424,1687,424,1690,424,1694,424,1696,424,1699,424,1701,424,1703,424,1705,424,1707,424,1709,424,1711,424,1713,424,1715,424,1717,424,1719,424,1721,424,1723,424,1725,424,1727,424,1729,424,1731,424,1733,424,1735,424,1737,424,1739,424,1741,424,1743,424,1745,424,1747,424,1749,424,1752,424,1754,424,1756,424,1758,424,1760,424,1762,424,1764,424,1766,424,1768,424,1770,424,1772,424,1774,424,1777,424,1779,424,1781,424,1783,424,1785,424,1788,424,1791,424,1794,424,1798,424,1800,424,1803,424,1805,424,1807,424,1809,424,1811,424,1813,424,1815,424,1817,424,1820,424,1822,424,1824,424,1826,424,1828,424,1830,424,1832,424,1834,424,1836,424,1838,424,1840,424,1842,424,1844,424,1846,424,1848,424,1850,424,1852,424,1854,424,1857,424,1859,424,1862,424,1864,424,1869,424,1871,424,1873,424,1875,424,1877,424,1879,424,1884,424,1886,424,1888,424,1890,424,1892,424,1894,424,1896,424,1899,424,1903,424,1905,424,1908,424,1910,424,1912,424,1914,424,1916,424,1918,424,1920,424,1922,424,1924,424,1926,424,1928,424,1930,424,1932,424,1934,424,1936,424,1938,424,1941,424,1943,424,1945,424,1947,424,1949,424,1951,424,1953,424,1955,424,1957,424,1959,424,1964,424,1966],{"viewBox":1345,"role":418,"ariaLabelledBy":1346,"xmlns":422,"style":1349},"4 0 12492 276",[1347,1348],"csv-checklist-t","csv-checklist-d","width:100%;max-width:12492px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif",[426,1351,1352],{"id":1347},"Settings that decide how a CSV opens in Excel",[430,1354,1355],{"id":1348},"A checklist of CSV problems and the to_csv setting that fixes each. Garbled accents need the UTF-8 BOM. Everything in column A needs the right separator. Numbers read as text need the matching decimal mark. Lost leading zeros need text protection or an xlsx. Swapped days and months need ISO dates. Broken rows need default quoting.",[434,1357],{"x":877,"y":437,"width":1358,"height":1359,"fill":440},"12492","276",[434,1361],{"x":930,"y":883,"width":1362,"height":444,"rx":437,"fill":440,"stroke":448,"style":449},"186.4",[434,1364],{"x":1365,"y":883,"width":1366,"height":444,"rx":437,"fill":480,"stroke":481,"style":615},"206.4","533.6",[455,1368,1372],{"x":1369,"y":1370,"style":1371},"473.2","41.0","font-size:13px;font-weight:700;fill:var(--brand-strong,#4338ca);text-anchor:middle","to_csv setting",[434,1374],{"x":930,"y":1375,"width":1362,"height":1376,"rx":437,"fill":447,"stroke":448,"style":449},"56.0","34.0",[455,1378,1381],{"x":445,"y":1379,"style":1380},"78.0","font-size:12.5px;font-weight:700;fill:var(--text,#172033);text-anchor:start","Garbled accents",[434,1383],{"x":1365,"y":1375,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1385,1387],{"x":1369,"y":1386,"style":949},"77.0","e",[434,1389],{"x":1390,"y":1375,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"740.0",[887,1392,1394],{"transform":1393},"translate(998.8,65.0) scale(0.667)",[891,1395],{"d":1396,"fill":894,"stroke":1397,"style":1398},"M6 6l12 12 M18 6L6 18","var(--accent,#f43f8f)","stroke-width:2.70px;stroke-linecap:round;stroke-linejoin:round",[434,1400],{"x":1401,"y":1375,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"1273.6",[455,1403,1405],{"x":1404,"y":1386,"style":949},"1540.5","c",[434,1407],{"x":1408,"y":1375,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"1807.3",[455,1410,1412],{"x":1411,"y":1386,"style":949},"2074.1","o",[434,1414],{"x":1415,"y":1375,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"2340.9",[455,1417,1419],{"x":1418,"y":1386,"style":949},"2607.8","d",[434,1421],{"x":1422,"y":1375,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"2874.6",[455,1424,1426],{"x":1425,"y":1386,"style":949},"3141.4","i",[434,1428],{"x":1429,"y":1375,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"3408.2",[887,1431,1433],{"transform":1432},"translate(3667.1,65.0) scale(0.667)",[891,1434],{"d":1396,"fill":894,"stroke":1397,"style":1398},[434,1436],{"x":1437,"y":1375,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"3941.9",[455,1439,887],{"x":1440,"y":1386,"style":949},"4208.7",[434,1442],{"x":1443,"y":1375,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"4475.5",[455,1445,129],{"x":1446,"y":1386,"style":949},"4742.4",[434,1448],{"x":1449,"y":1375,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"5009.2",[455,1451,794],{"x":1452,"y":1386,"style":949},"5276.0",[434,1454],{"x":1455,"y":1375,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"5542.8",[455,1457,1459],{"x":1458,"y":1386,"style":949},"5809.6","u",[434,1461],{"x":1462,"y":1375,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"6076.5",[455,1464,1466],{"x":1465,"y":1386,"style":949},"6343.3","t",[434,1468],{"x":1469,"y":1375,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"6610.1",[455,1471,1473],{"x":1472,"y":1386,"style":949},"6876.9","f",[434,1475],{"x":1476,"y":1375,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"7143.8",[887,1478,1480],{"transform":1479},"translate(7402.6,65.0) scale(0.667)",[891,1481],{"d":1396,"fill":894,"stroke":1397,"style":1398},[434,1483],{"x":1484,"y":1375,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"7677.4",[455,1486,1488],{"x":1487,"y":1386,"style":949},"7944.2","8",[434,1490],{"x":1491,"y":1375,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"8211.1",[887,1493,1495],{"transform":1494},"translate(8469.9,65.0) scale(0.667)",[891,1496],{"d":1396,"fill":894,"stroke":1397,"style":1398},[434,1498],{"x":1499,"y":1375,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"8744.7",[455,1501,1503],{"x":1502,"y":1386,"style":949},"9011.5","s",[434,1505],{"x":1506,"y":1375,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"9278.4",[455,1508,1426],{"x":1509,"y":1386,"style":949},"9545.2",[434,1511],{"x":1512,"y":1375,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"9812.0",[455,1514,887],{"x":1515,"y":1386,"style":949},"10078.8",[434,1517],{"x":1518,"y":1375,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"10345.6",[455,1520,794],{"x":1521,"y":1386,"style":949},"10612.5",[434,1523],{"x":930,"y":1524,"width":1362,"height":1376,"rx":437,"fill":447,"stroke":448,"style":449},"90.0",[455,1526,1528],{"x":445,"y":1527,"style":1380},"112.0","Everything in column A",[434,1530],{"x":1365,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1532,1503],{"x":1369,"y":497,"style":949},[434,1534],{"x":1390,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1536,1387],{"x":1537,"y":497,"style":949},"1006.8",[434,1539],{"x":1401,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1541,10],{"x":1404,"y":497,"style":949},[434,1543],{"x":1408,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1545,129],{"x":1411,"y":497,"style":949},[434,1547],{"x":1415,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1549,794],{"x":1418,"y":497,"style":949},[434,1551],{"x":1422,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1553,1554],{"x":1425,"y":497,"style":949},";",[434,1556],{"x":1429,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1558,794],{"x":1559,"y":497,"style":949},"3675.1",[434,1561],{"x":1437,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1563],{"x":1440,"y":497,"style":949},[434,1565],{"x":1443,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1567,748],{"x":1446,"y":497,"style":949},[434,1569],{"x":1449,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1571,1412],{"x":1452,"y":497,"style":949},[434,1573],{"x":1455,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1575,1576],{"x":1458,"y":497,"style":949},"r",[434,1578],{"x":1462,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1580],{"x":1465,"y":497,"style":949},[434,1582],{"x":1469,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1584,1503],{"x":1472,"y":497,"style":949},[434,1586],{"x":1476,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1588,1387],{"x":1589,"y":497,"style":949},"7410.6",[434,1591],{"x":1484,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1593,10],{"x":1487,"y":497,"style":949},[434,1595],{"x":1491,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1597,129],{"x":1598,"y":497,"style":949},"8477.9",[434,1600],{"x":1499,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1602],{"x":1502,"y":497,"style":949},[434,1604],{"x":1506,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1606,1607],{"x":1509,"y":497,"style":949},"h",[434,1609],{"x":1512,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1611,1426],{"x":1515,"y":497,"style":949},[434,1613],{"x":1518,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[887,1615,1617],{"transform":1616},"translate(10604.5,99.0) scale(0.667)",[891,1618],{"d":1396,"fill":894,"stroke":1397,"style":1398},[434,1620],{"x":1621,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"10879.3",[455,1623,1466],{"x":1624,"y":497,"style":949},"11146.1",[434,1626],{"x":1627,"y":1524,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"11412.9",[455,1629,1631],{"x":1630,"y":497,"style":949},"11679.8",")",[434,1633],{"x":930,"y":1634,"width":1362,"height":1376,"rx":437,"fill":447,"stroke":448,"style":449},"124.0",[455,1636,1638],{"x":445,"y":1637,"style":1380},"146.0","Numbers stay text",[434,1640],{"x":1365,"y":1634,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1642,1419],{"x":1369,"y":1643,"style":949},"145.0",[434,1645],{"x":1390,"y":1634,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1647,1387],{"x":1537,"y":1643,"style":949},[434,1649],{"x":1401,"y":1634,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1651,1405],{"x":1404,"y":1643,"style":949},[434,1653],{"x":1408,"y":1634,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1655,1426],{"x":1411,"y":1643,"style":949},[434,1657],{"x":1415,"y":1634,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1659,1660],{"x":1418,"y":1643,"style":949},"m",[434,1662],{"x":1422,"y":1634,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1664,39],{"x":1425,"y":1643,"style":949},[434,1666],{"x":1429,"y":1634,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1668,1669],{"x":1559,"y":1643,"style":949},"l",[434,1671],{"x":1437,"y":1634,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1673,129],{"x":1440,"y":1643,"style":949},[434,1675],{"x":1443,"y":1634,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1677,794],{"x":1446,"y":1643,"style":949},[434,1679],{"x":1449,"y":1634,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1681,1682],{"x":1452,"y":1643,"style":949},",",[434,1684],{"x":1455,"y":1634,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1686,794],{"x":1458,"y":1643,"style":949},[434,1688],{"x":930,"y":1689,"width":1362,"height":1376,"rx":437,"fill":447,"stroke":448,"style":449},"158.0",[455,1691,1693],{"x":445,"y":1692,"style":1380},"180.0","Leading zeros vanish",[434,1695],{"x":1365,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1697,129],{"x":1369,"y":1698,"style":949},"179.0",[434,1700],{"x":1390,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1702,794],{"x":1537,"y":1698,"style":949},[434,1704],{"x":1401,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1706,437],{"x":1404,"y":1698,"style":949},[434,1708],{"x":1408,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1710,437],{"x":1411,"y":1698,"style":949},[434,1712],{"x":1415,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1714,877],{"x":1418,"y":1698,"style":949},[434,1716],{"x":1422,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1718,477],{"x":1425,"y":1698,"style":949},[434,1720],{"x":1429,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1722,498],{"x":1559,"y":1698,"style":949},[434,1724],{"x":1437,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1726,794],{"x":1440,"y":1698,"style":949},[434,1728],{"x":1443,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1730],{"x":1446,"y":1698,"style":949},[434,1732],{"x":1449,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1734,1466],{"x":1452,"y":1698,"style":949},[434,1736],{"x":1455,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1738,1576],{"x":1458,"y":1698,"style":949},[434,1740],{"x":1462,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1742,1426],{"x":1465,"y":1698,"style":949},[434,1744],{"x":1469,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1746,1405],{"x":1472,"y":1698,"style":949},[434,1748],{"x":1476,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1750,1751],{"x":1589,"y":1698,"style":949},"k",[434,1753],{"x":1484,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1755,1682],{"x":1487,"y":1698,"style":949},[434,1757],{"x":1491,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1759],{"x":1598,"y":1698,"style":949},[434,1761],{"x":1499,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1763,1412],{"x":1502,"y":1698,"style":949},[434,1765],{"x":1506,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1767,1576],{"x":1509,"y":1698,"style":949},[434,1769],{"x":1512,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1771],{"x":1515,"y":1698,"style":949},[434,1773],{"x":1518,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1775,1776],{"x":1521,"y":1698,"style":949},"x",[434,1778],{"x":1621,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1780,1669],{"x":1624,"y":1698,"style":949},[434,1782],{"x":1627,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1784,1503],{"x":1630,"y":1698,"style":949},[434,1786],{"x":1787,"y":1689,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},"11946.6",[455,1789,1776],{"x":1790,"y":1698,"style":949},"12213.4",[434,1792],{"x":930,"y":1793,"width":1362,"height":1376,"rx":437,"fill":447,"stroke":448,"style":449},"192.0",[455,1795,1797],{"x":445,"y":1796,"style":1380},"214.0","Day and month swapped",[434,1799],{"x":1365,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1801,1419],{"x":1369,"y":1802,"style":949},"213.0",[434,1804],{"x":1390,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1806,39],{"x":1537,"y":1802,"style":949},[434,1808],{"x":1401,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1810,1466],{"x":1404,"y":1802,"style":949},[434,1812],{"x":1408,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1814,1387],{"x":1411,"y":1802,"style":949},[434,1816],{"x":1415,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1818,1819],{"x":1418,"y":1802,"style":949},"_",[434,1821],{"x":1422,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1823,1473],{"x":1425,"y":1802,"style":949},[434,1825],{"x":1429,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1827,1412],{"x":1559,"y":1802,"style":949},[434,1829],{"x":1437,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1831,1576],{"x":1440,"y":1802,"style":949},[434,1833],{"x":1443,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1835,1660],{"x":1446,"y":1802,"style":949},[434,1837],{"x":1449,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1839,39],{"x":1452,"y":1802,"style":949},[434,1841],{"x":1455,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1843,1466],{"x":1458,"y":1802,"style":949},[434,1845],{"x":1462,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1847,129],{"x":1465,"y":1802,"style":949},[434,1849],{"x":1469,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1851,794],{"x":1472,"y":1802,"style":949},[434,1853],{"x":1476,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1855,1856],{"x":1589,"y":1802,"style":949},"%",[434,1858],{"x":1484,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1860,1861],{"x":1487,"y":1802,"style":949},"Y",[434,1863],{"x":1491,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[887,1865,1867],{"transform":1866},"translate(8469.9,201.0) scale(0.667)",[891,1868],{"d":1396,"fill":894,"stroke":1397,"style":1398},[434,1870],{"x":1499,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1872,1856],{"x":1502,"y":1802,"style":949},[434,1874],{"x":1506,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1876,1660],{"x":1509,"y":1802,"style":949},[434,1878],{"x":1512,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[887,1880,1882],{"transform":1881},"translate(10070.8,201.0) scale(0.667)",[891,1883],{"d":1396,"fill":894,"stroke":1397,"style":1398},[434,1885],{"x":1518,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1887,1856],{"x":1521,"y":1802,"style":949},[434,1889],{"x":1621,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1891,1419],{"x":1624,"y":1802,"style":949},[434,1893],{"x":1627,"y":1793,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1895,794],{"x":1630,"y":1802,"style":949},[434,1897],{"x":930,"y":1898,"width":1362,"height":1376,"rx":437,"fill":447,"stroke":448,"style":449},"226.0",[455,1900,1902],{"x":445,"y":1901,"style":1380},"248.0","Rows broken by notes",[434,1904],{"x":1365,"y":1898,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1906,1419],{"x":1369,"y":1907,"style":949},"247.0",[434,1909],{"x":1390,"y":1898,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1911,1387],{"x":1537,"y":1907,"style":949},[434,1913],{"x":1401,"y":1898,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1915,1473],{"x":1404,"y":1907,"style":949},[434,1917],{"x":1408,"y":1898,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1919,39],{"x":1411,"y":1907,"style":949},[434,1921],{"x":1415,"y":1898,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1923,1459],{"x":1418,"y":1907,"style":949},[434,1925],{"x":1422,"y":1898,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1927,1669],{"x":1425,"y":1907,"style":949},[434,1929],{"x":1429,"y":1898,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1931,1466],{"x":1559,"y":1907,"style":949},[434,1933],{"x":1437,"y":1898,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1935],{"x":1440,"y":1907,"style":949},[434,1937],{"x":1443,"y":1898,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1939,1940],{"x":1446,"y":1907,"style":949},"q",[434,1942],{"x":1449,"y":1898,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1944,1459],{"x":1452,"y":1907,"style":949},[434,1946],{"x":1455,"y":1898,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1948,1412],{"x":1458,"y":1907,"style":949},[434,1950],{"x":1462,"y":1898,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1952,1466],{"x":1465,"y":1907,"style":949},[434,1954],{"x":1469,"y":1898,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1956,1426],{"x":1472,"y":1907,"style":949},[434,1958],{"x":1476,"y":1898,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[887,1960,1962],{"transform":1961},"translate(7402.6,235.0) scale(0.667)",[891,1963],{"d":1396,"fill":894,"stroke":1397,"style":1398},[434,1965],{"x":1484,"y":1898,"width":1366,"height":1376,"rx":437,"fill":440,"stroke":448,"style":449},[455,1967,887],{"x":1487,"y":1907,"style":949},[45,1969,1971],{"id":1970},"step-6-know-when-csv-is-the-wrong-format","Step 6 — Know when CSV is the wrong format",[10,1973,1974,1975,1978,1979,1981,1982,1985],{},"Everything above works around one fact: CSV carries no types, and Excel guesses. When the file must preserve text IDs, exact long numbers, real dates ",[630,1976,1977],{},"and"," look right to people in different countries, an ",[14,1980,36],{}," written with ",[14,1983,1984],{},"to_excel"," simply stores each cell's type and needs no guessing at all:",[50,1987,1989],{"className":79,"code":1988,"language":81,"meta":55,"style":55},"customers.to_excel(\"customers.xlsx\", index=False)\nfrom openpyxl import load_workbook\nws = load_workbook(\"customers.xlsx\").active\nprint(ws[\"A2\"].value, ws[\"A2\"].data_type, \"|\", ws[\"D2\"].value, ws[\"D2\"].data_type)\n",[14,1990,1991,2009,2021,2036],{"__ignoreMap":55},[59,1992,1993,1996,1999,2001,2003,2005,2007],{"class":61,"line":62},[59,1994,1995],{"class":92},"customers.to_excel(",[59,1997,1998],{"class":69},"\"customers.xlsx\"",[59,2000,147],{"class":92},[59,2002,324],{"class":323},[59,2004,129],{"class":88},[59,2006,329],{"class":192},[59,2008,332],{"class":92},[59,2010,2011,2013,2016,2018],{"class":61,"line":102},[59,2012,89],{"class":88},[59,2014,2015],{"class":92}," openpyxl ",[59,2017,96],{"class":88},[59,2019,2020],{"class":92}," load_workbook\n",[59,2022,2023,2026,2028,2031,2033],{"class":61,"line":116},[59,2024,2025],{"class":92},"ws ",[59,2027,129],{"class":88},[59,2029,2030],{"class":92}," load_workbook(",[59,2032,1998],{"class":69},[59,2034,2035],{"class":92},").active\n",[59,2037,2038,2040,2043,2046,2049,2051,2054,2057,2060,2063,2065,2067],{"class":61,"line":123},[59,2039,298],{"class":192},[59,2041,2042],{"class":92},"(ws[",[59,2044,2045],{"class":69},"\"A2\"",[59,2047,2048],{"class":92},"].value, ws[",[59,2050,2045],{"class":69},[59,2052,2053],{"class":92},"].data_type, ",[59,2055,2056],{"class":69},"\"|\"",[59,2058,2059],{"class":92},", ws[",[59,2061,2062],{"class":69},"\"D2\"",[59,2064,2048],{"class":92},[59,2066,2062],{"class":69},[59,2068,2069],{"class":92},"].data_type)\n",[10,2071,2072,2073,2075,2076,2078,2079,43],{},"The customer ID stays ",[14,2074,24],{}," as text and the reference keeps all 16 digits. Send CSV when the consumer is another program or when the user explicitly asked for it; send ",[14,2077,36],{}," when a person will open the file. The trade-offs are compared in ",[39,2080,2082],{"href":2081},"\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",[45,2084,2086],{"id":2085},"common-pitfalls","Common pitfalls",[2088,2089,2090,2100,2111,2117,2125],"ul",{},[2091,2092,2093,2097,2098,43],"li",{},[2094,2095,2096],"strong",{},"Plain UTF-8 without the BOM."," Valid, and garbled in Windows Excel; use ",[14,2099,397],{},[2091,2101,2102,2105,2106,2108,2109,43],{},[2094,2103,2104],{},"Comma files for European users."," One column per row; use ",[14,2107,712],{}," with ",[14,2110,716],{},[2091,2112,2113,2116],{},[2094,2114,2115],{},"Mixing separator and decimal mark."," Decimal commas inside comma-separated files split numbers across columns.",[2091,2118,2119,2122,2123,43],{},[2094,2120,2121],{},"Expecting leading zeros to survive."," They never do by double-click unless protected; better, send ",[14,2124,36],{},[2091,2126,2127,2130,2131,2133,2134,2137],{},[2094,2128,2129],{},"Windows line endings."," pandas writes ",[14,2132,276],{},"; Excel copes either way, but pass ",[14,2135,2136],{},"lineterminator=\"\\r\\n\""," if a legacy system demands CRLF.",[45,2139,2141],{"id":2140},"performance-notes","Performance notes",[10,2143,2144,2147,2148,2150],{},[14,2145,2146],{},"to_csv"," is far faster than ",[14,2149,1984],{}," — a million rows write in seconds rather than minutes — which is one honest reason to choose CSV for very large extracts. The settings above cost nothing measurable. Remember Excel's own ceiling: 1,048,576 rows per sheet. A larger CSV opens truncated, with a warning that is easy to miss, so split big extracts or tell the recipient to load them through Power Query instead of double-clicking.",[45,2152,2154],{"id":2153},"conclusion","Conclusion",[10,2156,2157,2158,2160,2161,2163,2164,2166,2167,2170,2171,2173],{},"Write CSV for Excel with ",[14,2159,621],{},", match ",[14,2162,666],{}," and ",[14,2165,676],{}," to the reader's regional settings (or add the Excel-only ",[14,2168,2169],{},"sep="," hint line), write ISO dates, let pandas quote awkward text, and protect or avoid identifiers that look like numbers. When the file must keep types for people in more than one locale, send an ",[14,2172,36],{}," instead — it removes the guessing entirely.",[45,2175,2177],{"id":2176},"frequently-asked-questions","Frequently asked questions",[10,2179,2180,2183],{},[2094,2181,2182],{},"Why does Excel show strange characters like Ã¼ in my CSV?","\nThe file is UTF-8 without a byte order mark, so Excel decodes it with the local code page. Write it with encoding=\"utf-8-sig\" in pandas to_csv, which adds the mark Excel looks for.",[10,2185,2186,2189],{},[2094,2187,2188],{},"Why does my CSV open in a single column in Excel?","\nExcel splits on the list separator from the system's regional settings, which is a semicolon in many European locales. Write with sep=\";\" and decimal=\",\" for those users, or add a first line sep=; to tell Excel which separator to use.",[10,2191,2192,2195],{},[2094,2193,2194],{},"How do I keep leading zeros in a CSV opened in Excel?","\nCSV cannot mark a field as text, so Excel converts 00412 to 412. Writing the value as =\"00412\" makes Excel show it as text, but other programs then see that formula; sending an xlsx file with the column stored as text is the cleaner fix.",[10,2197,2198,2201],{},[2094,2199,2200],{},"What date format should I use in a CSV for Excel?","\nUse ISO dates, yyyy-mm-dd, with date_format=\"%Y-%m-%d\". Excel recognises them in every locale, while formats such as 04\u002F03\u002F2019 are read as different dates in different countries.",[45,2203,2205],{"id":2204},"related","Related",[2088,2207,2208,2214,2221,2228],{},[2091,2209,2210,2211,2213],{},"Up one level: ",[39,2212,42],{"href":41}," — moving data between formats.",[2091,2215,2216,2220],{},[39,2217,2219],{"href":2218},"\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"," — turning a CSV into a typed workbook.",[2091,2222,2223,2227],{},[39,2224,2226],{"href":2225},"\u002Fgetting-started-with-python-excel-automation\u002Fhandling-excel-file-formats-and-conversions\u002Fread-csv-exports-with-semicolons-and-decimal-commas\u002F","Read CSV Exports with Semicolons and Decimal Commas"," — the reading side of the same problem.",[2091,2229,2230,2234],{},[39,2231,2233],{"href":2232},"\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-unicodedecodeerror-when-reading-csv-files-saved-by-excel\u002F","Fix UnicodeDecodeError When Reading CSV Files Saved by Excel"," — when Excel's CSV comes back to Python.",[2236,2237,2238],"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 .sSjpA, html code.shiki .sSjpA{--shiki-default:#005CC5;--shiki-dark:#FF9492}html pre.shiki code .sa561, html code.shiki .sa561{--shiki-default:#E36209;--shiki-dark:#FFB757}",{"title":55,"searchDepth":102,"depth":102,"links":2240},[2241,2242,2243,2244,2245,2246,2247,2248,2249,2250,2251,2252],{"id":47,"depth":102,"text":48},{"id":304,"depth":102,"text":305},{"id":624,"depth":102,"text":625},{"id":1008,"depth":102,"text":1009},{"id":1171,"depth":102,"text":1172},{"id":1274,"depth":102,"text":1275},{"id":1970,"depth":102,"text":1971},{"id":2085,"depth":102,"text":2086},{"id":2140,"depth":102,"text":2141},{"id":2153,"depth":102,"text":2154},{"id":2176,"depth":102,"text":2177},{"id":2204,"depth":102,"text":2205},"2026-10-02","A CSV that looks fine in a text editor can open in Excel with garbled accents, everything crammed into column A, IDs stripped of leading zeros and long numbers in scientific notation. Write it with a UTF-8 byte order mark, the separator and decimal mark the reader's Excel expects, ISO dates, protected identifiers and safe quoting — or decide that the file should really be an .xlsx.","md",[2257,2259,2261,2263],{"q":2182,"a":2258},"The file is UTF-8 without a byte order mark, so Excel decodes it with the local code page. Write it with encoding=\"utf-8-sig\" in pandas to_csv, which adds the mark Excel looks for.",{"q":2188,"a":2260},"Excel splits on the list separator from the system's regional settings, which is a semicolon in many European locales. Write with sep=\";\" and decimal=\",\" for those users, or add a first line sep=; to tell Excel which separator to use.",{"q":2194,"a":2262},"CSV cannot mark a field as text, so Excel converts 00412 to 412. Writing the value as =\"00412\" makes Excel show it as text, but other programs then see that formula; sending an xlsx file with the column stored as text is the cleaner fix.",{"q":2200,"a":2264},"Use ISO dates, yyyy-mm-dd, with date_format=\"%Y-%m-%d\". Excel recognises them in every locale, while formats such as 04\u002F03\u002F2019 are read as different dates in different countries.","write csv files that open correctly in excel",null,{"breadcrumb":2268},[2269,2272,2275],{"name":2270,"item":2271},"Home","\u002F",{"name":2273,"item":2274},"Getting Started with Python Excel Automation","\u002Fgetting-started-with-python-excel-automation\u002F",{"name":42,"item":41},"\u002Fgetting-started-with-python-excel-automation\u002Fhandling-excel-file-formats-and-conversions\u002Fwrite-csv-files-that-open-correctly-in-excel",{"title":2278,"description":2279},"Write CSV Files That Open Correctly in Excel from Python","Make pandas to_csv output open cleanly in Excel: encoding=\"utf-8-sig\" for accents, sep=\";\" and decimal=\",\" for European locales, the sep= hint line, keeping leading zeros and long IDs, ISO dates, line breaks in cells, and when to send xlsx instead.","write-csv-files-that-open-correctly-in-excel","getting-started-with-python-excel-automation\u002Fhandling-excel-file-formats-and-conversions\u002Fwrite-csv-files-that-open-correctly-in-excel\u002Findex",[2283,2284],"file-formats","writing-excel","how-to","hkidE3LOH4yof1vVeMdXDzEpt_m_xaNtBLHnYK8OY8A",[2288,2292],{"title":2289,"path":2290,"stem":2291,"children":-1},"Work with Macro-Enabled .xlsm Files in openpyxl","\u002Fgetting-started-with-python-excel-automation\u002Fhandling-excel-file-formats-and-conversions\u002Fwork-with-macro-enabled-xlsm-files-in-openpyxl","getting-started-with-python-excel-automation\u002Fhandling-excel-file-formats-and-conversions\u002Fwork-with-macro-enabled-xlsm-files-in-openpyxl\u002Findex",{"title":2293,"path":2294,"stem":2295,"children":-1},"Reading Excel Files with Pandas","\u002Fgetting-started-with-python-excel-automation\u002Freading-excel-files-with-pandas","getting-started-with-python-excel-automation\u002Freading-excel-files-with-pandas\u002Findex",[2297,2299],{"path":2298,"title":42},"\u002Fgetting-started-with-python-excel-automation\u002Fhandling-excel-file-formats-and-conversions",{"path":2300,"title":2273},"\u002Fgetting-started-with-python-excel-automation",[],[2303,2306,2309,2312,2315,2319],{"path":2304,"title":2305,"kind":2285},"\u002Fadvanced-data-transformation-and-cleaning\u002Freading-excel-with-polars-and-arrow\u002Fconvert-excel-files-to-parquet-with-python","Convert Excel Files to Parquet with Python",{"path":2307,"title":2308,"kind":2285},"\u002Fadvanced-data-transformation-and-cleaning\u002Fworking-with-large-excel-files-in-python\u002Fconvert-excel-to-csv-with-python","Convert Excel to CSV with Python",{"path":2310,"title":2082,"kind":2311},"\u002Fgetting-started-with-python-excel-automation\u002Fchoosing-a-python-excel-library\u002Fexcel-vs-csv-vs-parquet-for-python-data-pipelines","compare",{"path":2313,"title":2314,"kind":2311},"\u002Fgetting-started-with-python-excel-automation\u002Fchoosing-a-python-excel-library\u002Fpick-an-excel-engine-for-xlsx-xlsm-xls-xlsb-and-ods","Pick an Excel Engine for .xlsx, .xlsm, .xls, .xlsb and .ods",{"path":2316,"title":2317,"kind":2318},"\u002Fadvanced-data-transformation-and-cleaning\u002Fcleaning-excel-data-with-pandas\u002Ffix-garbled-characters-in-excel-data","Fix Garbled Characters Like \"CafÃ©\" and \"â€™\" in Excel Data","fix",{"path":2320,"title":2321,"kind":2285},"\u002Fgetting-started-with-python-excel-automation\u002Fautomating-excel-with-com-and-pywin32\u002Fextract-vba-macro-code-from-an-excel-file","Extract VBA Macro Code from an Excel File",1790972064975]