[{"data":1,"prerenderedAt":2588},["ShallowReactive",2],{"doc:\u002Fgetting-started-with-python-excel-automation\u002Fwriting-dataframes-to-excel-with-pandas\u002Fhow-pandas-data-types-are-written-to-excel-cells":3,"surround:\u002Fgetting-started-with-python-excel-automation\u002Fwriting-dataframes-to-excel-with-pandas\u002Fhow-pandas-data-types-are-written-to-excel-cells":2554,"ancestors:\u002Fgetting-started-with-python-excel-automation\u002Fwriting-dataframes-to-excel-with-pandas\u002Fhow-pandas-data-types-are-written-to-excel-cells":2563,"children:\u002Fgetting-started-with-python-excel-automation\u002Fwriting-dataframes-to-excel-with-pandas\u002Fhow-pandas-data-types-are-written-to-excel-cells":2568,"related:\u002Fgetting-started-with-python-excel-automation\u002Fwriting-dataframes-to-excel-with-pandas\u002Fhow-pandas-data-types-are-written-to-excel-cells":2569},{"id":4,"title":5,"body":6,"dateModified":2520,"datePublished":2520,"description":2521,"extension":2522,"faq":2523,"keyword":2532,"kind":2533,"meta":2534,"navigation":145,"path":2543,"seo":2544,"slug":2547,"stem":2548,"topics":2549,"type":2552,"__hash__":2553},"docs\u002Fgetting-started-with-python-excel-automation\u002Fwriting-dataframes-to-excel-with-pandas\u002Fhow-pandas-data-types-are-written-to-excel-cells\u002Findex.md","How pandas Data Types Are Written to Excel Cells",{"type":7,"value":8,"toc":2505},"minimark",[9,32,37,68,79,83,520,524,720,743,1047,1059,1063,1083,1201,1236,1240,1260,1411,1433,1602,1606,1637,1801,1816,1820,1838,1984,2137,2141,2155,2304,2333,2337,2393,2397,2417,2421,2436,2440,2450,2456,2462,2468,2472,2501],[10,11,12,16,17,20,21,25,26,31],"p",{},[13,14,15],"code",{},"DataFrame.to_excel"," looks like a straight copy from DataFrame to worksheet, but Excel only has four kinds of cell value — number, text, boolean and error — plus number formats that make some numbers look like dates. Every pandas type has to be squeezed into one of those, and some of the choices pandas makes are surprising: durations become day counts that display as whole numbers, infinity becomes the text ",[13,18,19],{},"inf",", a 17-digit integer is silently rounded, and a timezone-aware column refuses to write at all. Knowing the mapping lets you convert columns ",[22,23,24],"em",{},"before"," writing, so the workbook holds what you meant rather than what was convenient. Everything here was checked by writing each type with both engines and reading the cells back with openpyxl. It belongs to ",[27,28,30],"a",{"href":29},"\u002Fgetting-started-with-python-excel-automation\u002Fwriting-dataframes-to-excel-with-pandas\u002F","Writing DataFrames to Excel with pandas",".",[33,34,36],"h2",{"id":35},"prerequisites","Prerequisites",[38,39,44],"pre",{"className":40,"code":41,"language":42,"meta":43,"style":43},"language-bash shiki shiki-themes github-light github-dark-high-contrast","pip install pandas openpyxl xlsxwriter\n","bash","",[13,45,46],{"__ignoreMap":43},[47,48,51,55,59,62,65],"span",{"class":49,"line":50},"line",1,[47,52,54],{"class":53},"sMTad","pip",[47,56,58],{"class":57},"srMev"," install",[47,60,61],{"class":57}," pandas",[47,63,64],{"class":57}," openpyxl",[47,66,67],{"class":57}," xlsxwriter\n",[10,69,70,71,74,75,78],{},"The results were the same for ",[13,72,73],{},"engine=\"xlsxwriter\""," (the default when it is installed) and ",[13,76,77],{},"engine=\"openpyxl\""," on pandas 3.0, openpyxl 3.1 and XlsxWriter 3.2.",[33,80,82],{"id":81},"step-1-write-one-column-of-every-type","Step 1 — Write one column of every type",[38,84,88],{"className":85,"code":86,"language":87,"meta":43,"style":43},"language-python shiki shiki-themes github-light github-dark-high-contrast","import datetime as dt\nimport decimal\nimport numpy as np\nimport pandas as pd\n\nsamples = {\n    \"int64\": pd.Series([1, 2], dtype=\"int64\"),\n    \"Int64 with NA\": pd.Series([1, None], dtype=\"Int64\"),\n    \"float with NaN\": [1.5, np.nan],\n    \"bool\": [True, False],\n    \"str\": [\"a\", None],\n    \"datetime64\": pd.to_datetime([\"2026-01-05 13:30\", \"2026-02-01 00:00\"]),\n    \"date objects\": [dt.date(2026, 1, 5), dt.date(2026, 2, 1)],\n    \"timedelta\": pd.to_timedelta([\"1 days 06:00:00\", \"0 days 00:30:00\"]),\n    \"category\": pd.Categorical([\"x\", \"y\"]),\n    \"Decimal\": [decimal.Decimal(\"1.10\"), decimal.Decimal(\"2.005\")],\n    \"inf\": [np.inf, -np.inf],\n    \"Period\": pd.period_range(\"2026-01\", periods=2, freq=\"M\"),\n    \"list\": [[1, 2], [3]],\n    \"17-digit int\": pd.Series([12345678901234567, 2], dtype=\"int64\"),\n}\nframe = pd.DataFrame(samples)\nframe.to_excel(\"types.xlsx\", index=False)\n","python",[13,89,90,106,114,127,140,147,159,193,219,234,253,270,290,327,346,365,385,400,433,457,482,488,499],{"__ignoreMap":43},[47,91,92,96,100,103],{"class":49,"line":50},[47,93,95],{"class":94},"s-kum","import",[47,97,99],{"class":98},"skGVy"," datetime ",[47,101,102],{"class":94},"as",[47,104,105],{"class":98}," dt\n",[47,107,109,111],{"class":49,"line":108},2,[47,110,95],{"class":94},[47,112,113],{"class":98}," decimal\n",[47,115,117,119,122,124],{"class":49,"line":116},3,[47,118,95],{"class":94},[47,120,121],{"class":98}," numpy ",[47,123,102],{"class":94},[47,125,126],{"class":98}," np\n",[47,128,130,132,135,137],{"class":49,"line":129},4,[47,131,95],{"class":94},[47,133,134],{"class":98}," pandas ",[47,136,102],{"class":94},[47,138,139],{"class":98}," pd\n",[47,141,143],{"class":49,"line":142},5,[47,144,146],{"emptyLinePlaceholder":145},true,"\n",[47,148,150,153,156],{"class":49,"line":149},6,[47,151,152],{"class":98},"samples ",[47,154,155],{"class":94},"=",[47,157,158],{"class":98}," {\n",[47,160,162,165,168,172,175,178,181,185,187,190],{"class":49,"line":161},7,[47,163,164],{"class":57},"    \"int64\"",[47,166,167],{"class":98},": pd.Series([",[47,169,171],{"class":170},"sP0c6","1",[47,173,174],{"class":98},", ",[47,176,177],{"class":170},"2",[47,179,180],{"class":98},"], ",[47,182,184],{"class":183},"sa561","dtype",[47,186,155],{"class":94},[47,188,189],{"class":57},"\"int64\"",[47,191,192],{"class":98},"),\n",[47,194,196,199,201,203,205,208,210,212,214,217],{"class":49,"line":195},8,[47,197,198],{"class":57},"    \"Int64 with NA\"",[47,200,167],{"class":98},[47,202,171],{"class":170},[47,204,174],{"class":98},[47,206,207],{"class":170},"None",[47,209,180],{"class":98},[47,211,184],{"class":183},[47,213,155],{"class":94},[47,215,216],{"class":57},"\"Int64\"",[47,218,192],{"class":98},[47,220,222,225,228,231],{"class":49,"line":221},9,[47,223,224],{"class":57},"    \"float with NaN\"",[47,226,227],{"class":98},": [",[47,229,230],{"class":170},"1.5",[47,232,233],{"class":98},", np.nan],\n",[47,235,237,240,242,245,247,250],{"class":49,"line":236},10,[47,238,239],{"class":57},"    \"bool\"",[47,241,227],{"class":98},[47,243,244],{"class":170},"True",[47,246,174],{"class":98},[47,248,249],{"class":170},"False",[47,251,252],{"class":98},"],\n",[47,254,256,259,261,264,266,268],{"class":49,"line":255},11,[47,257,258],{"class":57},"    \"str\"",[47,260,227],{"class":98},[47,262,263],{"class":57},"\"a\"",[47,265,174],{"class":98},[47,267,207],{"class":170},[47,269,252],{"class":98},[47,271,273,276,279,282,284,287],{"class":49,"line":272},12,[47,274,275],{"class":57},"    \"datetime64\"",[47,277,278],{"class":98},": pd.to_datetime([",[47,280,281],{"class":57},"\"2026-01-05 13:30\"",[47,283,174],{"class":98},[47,285,286],{"class":57},"\"2026-02-01 00:00\"",[47,288,289],{"class":98},"]),\n",[47,291,293,296,299,302,304,306,308,311,314,316,318,320,322,324],{"class":49,"line":292},13,[47,294,295],{"class":57},"    \"date objects\"",[47,297,298],{"class":98},": [dt.date(",[47,300,301],{"class":170},"2026",[47,303,174],{"class":98},[47,305,171],{"class":170},[47,307,174],{"class":98},[47,309,310],{"class":170},"5",[47,312,313],{"class":98},"), dt.date(",[47,315,301],{"class":170},[47,317,174],{"class":98},[47,319,177],{"class":170},[47,321,174],{"class":98},[47,323,171],{"class":170},[47,325,326],{"class":98},")],\n",[47,328,330,333,336,339,341,344],{"class":49,"line":329},14,[47,331,332],{"class":57},"    \"timedelta\"",[47,334,335],{"class":98},": pd.to_timedelta([",[47,337,338],{"class":57},"\"1 days 06:00:00\"",[47,340,174],{"class":98},[47,342,343],{"class":57},"\"0 days 00:30:00\"",[47,345,289],{"class":98},[47,347,349,352,355,358,360,363],{"class":49,"line":348},15,[47,350,351],{"class":57},"    \"category\"",[47,353,354],{"class":98},": pd.Categorical([",[47,356,357],{"class":57},"\"x\"",[47,359,174],{"class":98},[47,361,362],{"class":57},"\"y\"",[47,364,289],{"class":98},[47,366,368,371,374,377,380,383],{"class":49,"line":367},16,[47,369,370],{"class":57},"    \"Decimal\"",[47,372,373],{"class":98},": [decimal.Decimal(",[47,375,376],{"class":57},"\"1.10\"",[47,378,379],{"class":98},"), decimal.Decimal(",[47,381,382],{"class":57},"\"2.005\"",[47,384,326],{"class":98},[47,386,388,391,394,397],{"class":49,"line":387},17,[47,389,390],{"class":57},"    \"inf\"",[47,392,393],{"class":98},": [np.inf, ",[47,395,396],{"class":94},"-",[47,398,399],{"class":98},"np.inf],\n",[47,401,403,406,409,412,414,417,419,421,423,426,428,431],{"class":49,"line":402},18,[47,404,405],{"class":57},"    \"Period\"",[47,407,408],{"class":98},": pd.period_range(",[47,410,411],{"class":57},"\"2026-01\"",[47,413,174],{"class":98},[47,415,416],{"class":183},"periods",[47,418,155],{"class":94},[47,420,177],{"class":170},[47,422,174],{"class":98},[47,424,425],{"class":183},"freq",[47,427,155],{"class":94},[47,429,430],{"class":57},"\"M\"",[47,432,192],{"class":98},[47,434,436,439,442,444,446,448,451,454],{"class":49,"line":435},19,[47,437,438],{"class":57},"    \"list\"",[47,440,441],{"class":98},": [[",[47,443,171],{"class":170},[47,445,174],{"class":98},[47,447,177],{"class":170},[47,449,450],{"class":98},"], [",[47,452,453],{"class":170},"3",[47,455,456],{"class":98},"]],\n",[47,458,460,463,465,468,470,472,474,476,478,480],{"class":49,"line":459},20,[47,461,462],{"class":57},"    \"17-digit int\"",[47,464,167],{"class":98},[47,466,467],{"class":170},"12345678901234567",[47,469,174],{"class":98},[47,471,177],{"class":170},[47,473,180],{"class":98},[47,475,184],{"class":183},[47,477,155],{"class":94},[47,479,189],{"class":57},[47,481,192],{"class":98},[47,483,485],{"class":49,"line":484},21,[47,486,487],{"class":98},"}\n",[47,489,491,494,496],{"class":49,"line":490},22,[47,492,493],{"class":98},"frame ",[47,495,155],{"class":94},[47,497,498],{"class":98}," pd.DataFrame(samples)\n",[47,500,502,505,508,510,513,515,517],{"class":49,"line":501},23,[47,503,504],{"class":98},"frame.to_excel(",[47,506,507],{"class":57},"\"types.xlsx\"",[47,509,174],{"class":98},[47,511,512],{"class":183},"index",[47,514,155],{"class":94},[47,516,249],{"class":170},[47,518,519],{"class":98},")\n",[33,521,523],{"id":522},"step-2-read-back-what-each-cell-holds","Step 2 — Read back what each cell holds",[38,525,527],{"className":85,"code":526,"language":87,"meta":43,"style":43},"from openpyxl import load_workbook\n\nws = load_workbook(\"types.xlsx\").active\nprint(f\"{'column':15} {'stored value':28} {'type':4} number format\")\nfor col in ws.iter_cols(min_row=1, max_row=3):\n    header, first, second = col\n    print(f\"{header.value:15} {first.value!r:28} {first.data_type:4} {first.number_format}   next: {second.value!r}\")\n",[13,528,529,542,546,561,614,647,657],{"__ignoreMap":43},[47,530,531,534,537,539],{"class":49,"line":50},[47,532,533],{"class":94},"from",[47,535,536],{"class":98}," openpyxl ",[47,538,95],{"class":94},[47,540,541],{"class":98}," load_workbook\n",[47,543,544],{"class":49,"line":108},[47,545,146],{"emptyLinePlaceholder":145},[47,547,548,551,553,556,558],{"class":49,"line":116},[47,549,550],{"class":98},"ws ",[47,552,155],{"class":94},[47,554,555],{"class":98}," load_workbook(",[47,557,507],{"class":57},[47,559,560],{"class":98},").active\n",[47,562,563,566,569,572,575,579,582,585,588,591,594,597,599,601,604,607,609,612],{"class":49,"line":129},[47,564,565],{"class":170},"print",[47,567,568],{"class":98},"(",[47,570,571],{"class":94},"f",[47,573,574],{"class":57},"\"",[47,576,578],{"class":577},"sSjpA","{",[47,580,581],{"class":57},"'column'",[47,583,584],{"class":94},":15",[47,586,587],{"class":577},"}",[47,589,590],{"class":577}," {",[47,592,593],{"class":57},"'stored value'",[47,595,596],{"class":94},":28",[47,598,587],{"class":577},[47,600,590],{"class":577},[47,602,603],{"class":57},"'type'",[47,605,606],{"class":94},":4",[47,608,587],{"class":577},[47,610,611],{"class":57}," number format\"",[47,613,519],{"class":98},[47,615,616,619,622,625,628,631,633,635,637,640,642,644],{"class":49,"line":142},[47,617,618],{"class":94},"for",[47,620,621],{"class":98}," col ",[47,623,624],{"class":94},"in",[47,626,627],{"class":98}," ws.iter_cols(",[47,629,630],{"class":183},"min_row",[47,632,155],{"class":94},[47,634,171],{"class":170},[47,636,174],{"class":98},[47,638,639],{"class":183},"max_row",[47,641,155],{"class":94},[47,643,453],{"class":170},[47,645,646],{"class":98},"):\n",[47,648,649,652,654],{"class":49,"line":149},[47,650,651],{"class":98},"    header, first, second ",[47,653,155],{"class":94},[47,655,656],{"class":98}," col\n",[47,658,659,662,664,666,668,670,673,675,677,679,682,685,687,689,692,694,696,698,701,703,706,708,711,714,716,718],{"class":49,"line":161},[47,660,661],{"class":170},"    print",[47,663,568],{"class":98},[47,665,571],{"class":94},[47,667,574],{"class":57},[47,669,578],{"class":577},[47,671,672],{"class":98},"header.value",[47,674,584],{"class":94},[47,676,587],{"class":577},[47,678,590],{"class":577},[47,680,681],{"class":98},"first.value",[47,683,684],{"class":94},"!r:28",[47,686,587],{"class":577},[47,688,590],{"class":577},[47,690,691],{"class":98},"first.data_type",[47,693,606],{"class":94},[47,695,587],{"class":577},[47,697,590],{"class":577},[47,699,700],{"class":98},"first.number_format",[47,702,587],{"class":577},[47,704,705],{"class":57},"   next: ",[47,707,578],{"class":577},[47,709,710],{"class":98},"second.value",[47,712,713],{"class":94},"!r",[47,715,587],{"class":577},[47,717,574],{"class":57},[47,719,519],{"class":98},[10,721,722,723,726,727,730,731,734,735,738,739,742],{},"openpyxl's ",[13,724,725],{},"data_type"," is ",[13,728,729],{},"n"," for numbers (dates included — a date is a number with a date format), ",[13,732,733],{},"s"," for text, ",[13,736,737],{},"b"," for booleans and ",[13,740,741],{},"d"," when it recognises a date format on a number. Here is what came back:",[744,745,753,754,753,758,753,762,753,770,753,778,753,785,753,792,753,795,753,799,753,802,753,806,753,811,753,817,753,819,753,824,753,826,753,829,753,831,753,834,753,837,753,841,753,843,753,846,753,848,753,850,753,852,753,855,753,858,753,862,753,864,753,868,753,870,753,872,753,874,753,877,753,880,753,884,753,886,753,889,753,891,753,893,753,895,753,898,753,901,753,905,753,907,753,910,753,912,753,915,753,917,753,920,753,923,753,927,753,929,753,932,753,934,753,937,753,939,753,941,753,944,753,948,753,950,753,954,753,956,753,958,753,960,753,963,753,966,753,970,753,972,753,975,753,977,753,979,753,981,753,984,753,987,753,991,753,993,753,996,753,998,753,1000,753,1002,753,1005,753,1008,753,1012,753,1014,753,1017,753,1019,753,1021,753,1023,753,1026,753,1029,753,1033,753,1035,753,1038,753,1040,753,1042,753,1044],"svg",{"viewBox":746,"role":747,"ariaLabelledBy":748,"xmlns":751,"style":752},"4 0 752 446","img",[749,750],"dt-map-t","dt-map-d","http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg","width:100%;max-width:752px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif","\n  ",[755,756,757],"title",{"id":749},"What to_excel stores for each pandas type",[759,760,761],"desc",{"id":750},"A table with one row per pandas type and three columns showing the stored cell kind, the number format, and the surprise to watch for. Integers, floats and booleans map cleanly; datetime64 gets a date-time format; timedelta becomes a day count with format 0; inf, Period and lists become text; a 17-digit integer is rounded.",[763,764],"rect",{"x":765,"y":766,"width":767,"height":768,"fill":769},"4","0","752","446","#ffffff",[763,771],{"x":772,"y":773,"width":774,"height":775,"rx":766,"fill":769,"stroke":776,"style":777},"20.0","16.0","118.8","40.0","var(--line,#cdd5e6)","stroke-width:1px",[763,779],{"x":780,"y":773,"width":781,"height":775,"rx":766,"fill":782,"stroke":783,"style":784},"138.8","200.4","#f0f4ff","var(--brand,#5b5cf0)","stroke-width:1.2px",[786,787,791],"text",{"x":788,"y":789,"style":790},"239.0","41.0","font-size:13px;font-weight:700;fill:var(--brand-strong,#4338ca);text-anchor:middle","stored as",[763,793],{"x":794,"y":773,"width":781,"height":775,"rx":766,"fill":782,"stroke":783,"style":784},"339.2",[786,796,798],{"x":797,"y":789,"style":790},"439.4","number format",[763,800],{"x":801,"y":773,"width":781,"height":775,"rx":766,"fill":782,"stroke":783,"style":784},"539.6",[786,803,805],{"x":804,"y":789,"style":790},"639.8","watch for",[763,807],{"x":772,"y":808,"width":774,"height":809,"rx":766,"fill":810,"stroke":776,"style":777},"56.0","34.0","#e7ebef",[786,812,816],{"x":813,"y":814,"style":815},"32.0","78.0","font-size:12.5px;font-weight:700;fill:var(--text,#172033);text-anchor:start","int64 \u002F Int64",[763,818],{"x":780,"y":808,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,820,823],{"x":788,"y":821,"style":822},"77.0","font-size:11.5px;font-weight:400;fill:var(--text,#172033);text-anchor:middle","number",[763,825],{"x":794,"y":808,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,827,828],{"x":797,"y":821,"style":822},"General",[763,830],{"x":801,"y":808,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,832,833],{"x":804,"y":821,"style":822},"NA becomes an empty cell",[763,835],{"x":772,"y":836,"width":774,"height":809,"rx":766,"fill":810,"stroke":776,"style":777},"90.0",[786,838,840],{"x":813,"y":839,"style":815},"112.0","float64",[763,842],{"x":780,"y":836,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,844,823],{"x":788,"y":845,"style":822},"111.0",[763,847],{"x":794,"y":836,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,849,828],{"x":797,"y":845,"style":822},[763,851],{"x":801,"y":836,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,853,854],{"x":804,"y":845,"style":822},"NaN becomes an empty cell",[763,856],{"x":772,"y":857,"width":774,"height":809,"rx":766,"fill":810,"stroke":776,"style":777},"124.0",[786,859,861],{"x":813,"y":860,"style":815},"146.0","bool \u002F boolean",[763,863],{"x":780,"y":857,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,865,867],{"x":788,"y":866,"style":822},"145.0","TRUE \u002F FALSE",[763,869],{"x":794,"y":857,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,871,828],{"x":797,"y":866,"style":822},[763,873],{"x":801,"y":857,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,875,876],{"x":804,"y":866,"style":822},"none",[763,878],{"x":772,"y":879,"width":774,"height":809,"rx":766,"fill":810,"stroke":776,"style":777},"158.0",[786,881,883],{"x":813,"y":882,"style":815},"180.0","str \u002F category",[763,885],{"x":780,"y":879,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,887,786],{"x":788,"y":888,"style":822},"179.0",[763,890],{"x":794,"y":879,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,892,828],{"x":797,"y":888,"style":822},[763,894],{"x":801,"y":879,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,896,897],{"x":804,"y":888,"style":822},"category writes its labels",[763,899],{"x":772,"y":900,"width":774,"height":809,"rx":766,"fill":810,"stroke":776,"style":777},"192.0",[786,902,904],{"x":813,"y":903,"style":815},"214.0","datetime64",[763,906],{"x":780,"y":900,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,908,823],{"x":788,"y":909,"style":822},"213.0",[763,911],{"x":794,"y":900,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,913,914],{"x":797,"y":909,"style":822},"YYYY-MM-DD HH:MM:SS",[763,916],{"x":801,"y":900,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,918,919],{"x":804,"y":909,"style":822},"time shown even at midnight",[763,921],{"x":772,"y":922,"width":774,"height":809,"rx":766,"fill":810,"stroke":776,"style":777},"226.0",[786,924,926],{"x":813,"y":925,"style":815},"248.0","date objects",[763,928],{"x":780,"y":922,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,930,823],{"x":788,"y":931,"style":822},"247.0",[763,933],{"x":794,"y":922,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,935,936],{"x":797,"y":931,"style":822},"YYYY-MM-DD",[763,938],{"x":801,"y":922,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,940,876],{"x":804,"y":931,"style":822},[763,942],{"x":772,"y":943,"width":774,"height":809,"rx":766,"fill":810,"stroke":776,"style":777},"260.0",[786,945,947],{"x":813,"y":946,"style":815},"282.0","timedelta",[763,949],{"x":780,"y":943,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,951,953],{"x":788,"y":952,"style":822},"281.0","days as number",[763,955],{"x":794,"y":943,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,957,766],{"x":797,"y":952,"style":822},[763,959],{"x":801,"y":943,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,961,962],{"x":804,"y":952,"style":822},"1 d 6 h displays as 1",[763,964],{"x":772,"y":965,"width":774,"height":809,"rx":766,"fill":810,"stroke":776,"style":777},"294.0",[786,967,969],{"x":813,"y":968,"style":815},"316.0","Decimal",[763,971],{"x":780,"y":965,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,973,823],{"x":788,"y":974,"style":822},"315.0",[763,976],{"x":794,"y":965,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,978,828],{"x":797,"y":974,"style":822},[763,980],{"x":801,"y":965,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,982,983],{"x":804,"y":974,"style":822},"converted to float",[763,985],{"x":772,"y":986,"width":774,"height":809,"rx":766,"fill":810,"stroke":776,"style":777},"328.0",[786,988,990],{"x":813,"y":989,"style":815},"350.0","inf \u002F -inf",[763,992],{"x":780,"y":986,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,994,786],{"x":788,"y":995,"style":822},"349.0",[763,997],{"x":794,"y":986,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,999,828],{"x":797,"y":995,"style":822},[763,1001],{"x":801,"y":986,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,1003,1004],{"x":804,"y":995,"style":822},"the text inf, not a number",[763,1006],{"x":772,"y":1007,"width":774,"height":809,"rx":766,"fill":810,"stroke":776,"style":777},"362.0",[786,1009,1011],{"x":813,"y":1010,"style":815},"384.0","Period, list",[763,1013],{"x":780,"y":1007,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,1015,786],{"x":788,"y":1016,"style":822},"383.0",[763,1018],{"x":794,"y":1007,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,1020,828],{"x":797,"y":1016,"style":822},[763,1022],{"x":801,"y":1007,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,1024,1025],{"x":804,"y":1016,"style":822},"str() of the object",[763,1027],{"x":772,"y":1028,"width":774,"height":809,"rx":766,"fill":810,"stroke":776,"style":777},"396.0",[786,1030,1032],{"x":813,"y":1031,"style":815},"418.0","17-digit int",[763,1034],{"x":780,"y":1028,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,1036,823],{"x":788,"y":1037,"style":822},"417.0",[763,1039],{"x":794,"y":1028,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,1041,828],{"x":797,"y":1037,"style":822},[763,1043],{"x":801,"y":1028,"width":781,"height":809,"rx":766,"fill":769,"stroke":776,"style":777},[786,1045,1046],{"x":804,"y":1037,"style":822},"rounded to 15 digits",[10,1048,1049,1050,174,1053,174,1056,1058],{},"Integers, floats, booleans and plain text behave exactly as you would hope, and missing values (",[13,1051,1052],{},"NaN",[13,1054,1055],{},"\u003CNA>",[13,1057,207],{},") become empty cells by default. The rest of this page goes through the types that need attention.",[33,1060,1062],{"id":1061},"step-3-dates-and-datetimes","Step 3 — Dates and datetimes",[10,1064,1065,1066,1068,1069,1071,1072,1075,1076,1079,1080,1082],{},"A ",[13,1067,904],{}," column is written as an Excel date serial with the format ",[13,1070,914],{},", so even values at midnight display ",[13,1073,1074],{},"00:00:00",". A column of Python ",[13,1077,1078],{},"date"," objects (object dtype) gets ",[13,1081,936],{},". Choose the display yourself through the writer:",[38,1084,1086],{"className":85,"code":1085,"language":87,"meta":43,"style":43},"with pd.ExcelWriter(\"dates.xlsx\", engine=\"xlsxwriter\",\n                    datetime_format=\"dd mmm yyyy hh:mm\", date_format=\"dd mmm yyyy\") as xw:\n    frame[[\"datetime64\", \"date objects\"]].to_excel(xw, index=False)\nws = load_workbook(\"dates.xlsx\").active\nprint(ws[\"A2\"].number_format, \"|\", ws[\"B2\"].number_format)\n",[13,1087,1088,1112,1140,1164,1176],{"__ignoreMap":43},[47,1089,1090,1093,1096,1099,1101,1104,1106,1109],{"class":49,"line":50},[47,1091,1092],{"class":94},"with",[47,1094,1095],{"class":98}," pd.ExcelWriter(",[47,1097,1098],{"class":57},"\"dates.xlsx\"",[47,1100,174],{"class":98},[47,1102,1103],{"class":183},"engine",[47,1105,155],{"class":94},[47,1107,1108],{"class":57},"\"xlsxwriter\"",[47,1110,1111],{"class":98},",\n",[47,1113,1114,1117,1119,1122,1124,1127,1129,1132,1135,1137],{"class":49,"line":108},[47,1115,1116],{"class":183},"                    datetime_format",[47,1118,155],{"class":94},[47,1120,1121],{"class":57},"\"dd mmm yyyy hh:mm\"",[47,1123,174],{"class":98},[47,1125,1126],{"class":183},"date_format",[47,1128,155],{"class":94},[47,1130,1131],{"class":57},"\"dd mmm yyyy\"",[47,1133,1134],{"class":98},") ",[47,1136,102],{"class":94},[47,1138,1139],{"class":98}," xw:\n",[47,1141,1142,1145,1148,1150,1153,1156,1158,1160,1162],{"class":49,"line":116},[47,1143,1144],{"class":98},"    frame[[",[47,1146,1147],{"class":57},"\"datetime64\"",[47,1149,174],{"class":98},[47,1151,1152],{"class":57},"\"date objects\"",[47,1154,1155],{"class":98},"]].to_excel(xw, ",[47,1157,512],{"class":183},[47,1159,155],{"class":94},[47,1161,249],{"class":170},[47,1163,519],{"class":98},[47,1165,1166,1168,1170,1172,1174],{"class":49,"line":129},[47,1167,550],{"class":98},[47,1169,155],{"class":94},[47,1171,555],{"class":98},[47,1173,1098],{"class":57},[47,1175,560],{"class":98},[47,1177,1178,1180,1183,1186,1189,1192,1195,1198],{"class":49,"line":142},[47,1179,565],{"class":170},[47,1181,1182],{"class":98},"(ws[",[47,1184,1185],{"class":57},"\"A2\"",[47,1187,1188],{"class":98},"].number_format, ",[47,1190,1191],{"class":57},"\"|\"",[47,1193,1194],{"class":98},", ws[",[47,1196,1197],{"class":57},"\"B2\"",[47,1199,1200],{"class":98},"].number_format)\n",[10,1202,1203,1206,1207,1209,1210,1212,1213,1215,1216,1219,1220,1223,1224,1228,1229,1232,1233,31],{},[13,1204,1205],{},"datetime_format"," applies to datetime columns and ",[13,1208,1126],{}," only to ",[13,1211,1078],{}," objects. Both are honoured by the xlsxwriter engine; the openpyxl engine ignores ",[13,1214,1205],{},", so either use xlsxwriter or set ",[13,1217,1218],{},"cell.number_format"," afterwards. To drop the time part entirely, convert with ",[13,1221,1222],{},".dt.date"," before writing, as described in ",[27,1225,1227],{"href":1226},"\u002Fgetting-started-with-python-excel-automation\u002Fwriting-dataframes-to-excel-with-pandas\u002Fwrite-dates-without-time-from-pandas-to-excel\u002F","Write Dates Without Time from pandas to Excel",". Timezone-aware columns are rejected with ",[13,1230,1231],{},"ValueError: Excel does not support datetimes with timezones","; convert to the zone the reader expects and remove the zone with ",[13,1234,1235],{},".dt.tz_convert(\"Europe\u002FBerlin\").dt.tz_localize(None)",[33,1237,1239],{"id":1238},"step-4-durations","Step 4 — Durations",[10,1241,1242,1243,1246,1247,1250,1251,1253,1254,1256,1257,1259],{},"A timedelta is stored as a fraction of days — 1 day 6 hours becomes ",[13,1244,1245],{},"1.25",", 30 minutes becomes ",[13,1248,1249],{},"0.0208"," — with the number format ",[13,1252,766],{},", which rounds the display to a whole number. Excel therefore shows ",[13,1255,171],{}," and ",[13,1258,766],{},". The value is right; the format hides it. Give the column a duration format:",[38,1261,1263],{"className":85,"code":1262,"language":87,"meta":43,"style":43},"with pd.ExcelWriter(\"durations.xlsx\", engine=\"xlsxwriter\") as xw:\n    frame[[\"timedelta\"]].to_excel(xw, index=False)\n    hours = xw.book.add_format({\"num_format\": \"[h]:mm\"})\n    for row in range(1, 3):\n        xw.sheets[\"Sheet1\"].write_number(row, 0, frame[\"timedelta\"][row - 1] \u002F pd.Timedelta(days=1), hours)\nprint(load_workbook(\"durations.xlsx\").active[\"A2\"].number_format)\n",[13,1264,1265,1288,1305,1327,1350,1395],{"__ignoreMap":43},[47,1266,1267,1269,1271,1274,1276,1278,1280,1282,1284,1286],{"class":49,"line":50},[47,1268,1092],{"class":94},[47,1270,1095],{"class":98},[47,1272,1273],{"class":57},"\"durations.xlsx\"",[47,1275,174],{"class":98},[47,1277,1103],{"class":183},[47,1279,155],{"class":94},[47,1281,1108],{"class":57},[47,1283,1134],{"class":98},[47,1285,102],{"class":94},[47,1287,1139],{"class":98},[47,1289,1290,1292,1295,1297,1299,1301,1303],{"class":49,"line":108},[47,1291,1144],{"class":98},[47,1293,1294],{"class":57},"\"timedelta\"",[47,1296,1155],{"class":98},[47,1298,512],{"class":183},[47,1300,155],{"class":94},[47,1302,249],{"class":170},[47,1304,519],{"class":98},[47,1306,1307,1310,1312,1315,1318,1321,1324],{"class":49,"line":116},[47,1308,1309],{"class":98},"    hours ",[47,1311,155],{"class":94},[47,1313,1314],{"class":98}," xw.book.add_format({",[47,1316,1317],{"class":57},"\"num_format\"",[47,1319,1320],{"class":98},": ",[47,1322,1323],{"class":57},"\"[h]:mm\"",[47,1325,1326],{"class":98},"})\n",[47,1328,1329,1332,1335,1337,1340,1342,1344,1346,1348],{"class":49,"line":129},[47,1330,1331],{"class":94},"    for",[47,1333,1334],{"class":98}," row ",[47,1336,624],{"class":94},[47,1338,1339],{"class":170}," range",[47,1341,568],{"class":98},[47,1343,171],{"class":170},[47,1345,174],{"class":98},[47,1347,453],{"class":170},[47,1349,646],{"class":98},[47,1351,1352,1355,1358,1361,1363,1366,1368,1371,1373,1376,1379,1382,1385,1388,1390,1392],{"class":49,"line":142},[47,1353,1354],{"class":98},"        xw.sheets[",[47,1356,1357],{"class":57},"\"Sheet1\"",[47,1359,1360],{"class":98},"].write_number(row, ",[47,1362,766],{"class":170},[47,1364,1365],{"class":98},", frame[",[47,1367,1294],{"class":57},[47,1369,1370],{"class":98},"][row ",[47,1372,396],{"class":94},[47,1374,1375],{"class":170}," 1",[47,1377,1378],{"class":98},"] ",[47,1380,1381],{"class":94},"\u002F",[47,1383,1384],{"class":98}," pd.Timedelta(",[47,1386,1387],{"class":183},"days",[47,1389,155],{"class":94},[47,1391,171],{"class":170},[47,1393,1394],{"class":98},"), hours)\n",[47,1396,1397,1399,1402,1404,1407,1409],{"class":49,"line":149},[47,1398,565],{"class":170},[47,1400,1401],{"class":98},"(load_workbook(",[47,1403,1273],{"class":57},[47,1405,1406],{"class":98},").active[",[47,1408,1185],{"class":57},[47,1410,1200],{"class":98},[10,1412,1413,1416,1417,1420,1421,1424,1425,1428,1429,31],{},[13,1414,1415],{},"[h]:mm"," shows ",[13,1418,1419],{},"30:00"," for 1.25 days; the square brackets stop hours wrapping at 24. Rewriting the cells is needed because pandas' per-cell format overrides a column format set with ",[13,1422,1423],{},"set_column",". If the reader wants plain numbers instead, write hours as floats: ",[13,1426,1427],{},"frame[\"timedelta\"].dt.total_seconds() \u002F 3600",". More formats are in ",[27,1430,1432],{"href":1431},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fapplying-number-and-date-formats-in-excel\u002Fformat-durations-over-24-hours-in-excel\u002F","Format Durations Over 24 Hours in Excel",[744,1434,753,1440,753,1443,753,1446,753,1451,753,1455,753,1460,753,1463,753,1468,753,1471,753,1475,753,1479,753,1483,753,1489,753,1493,753,1497,753,1501,753,1505,753,1508,753,1512,753,1515,753,1519,753,1521,753,1524,753,1526,753,1528,753,1531,753,1533,753,1535,753,1537,753,1541,753,1544,753,1548,753,1551,753,1554,753,1557,753,1559,753,1561,753,1563,753,1565,753,1567,753,1570,753,1575,753,1579,753,1585,753,1590,753,1597],{"viewBox":1435,"role":747,"ariaLabelledBy":1436,"xmlns":751,"style":1439},"118 0 560 164",[1437,1438],"dt-duration-t","dt-duration-d","width:100%;max-width:560px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif",[755,1441,1442],{"id":1437},"A timedelta is written as days with a format that hides the fraction",[759,1444,1445],{"id":1438},"The pandas column holds 1 day 6 hours and 30 minutes. The workbook stores 1.25 and 0.0208 with number format 0, so Excel displays 1 and 0. With the format [h]:mm the same values display 30:00 and 0:30.",[763,1447],{"x":1448,"y":766,"width":1449,"height":1450,"fill":769},"118","560","164",[763,1452],{"x":1453,"y":775,"width":774,"height":1454,"rx":766,"fill":769,"stroke":776,"style":777},"134.1","28.0",[786,1456,947],{"x":1457,"y":1458,"style":1459},"193.5","59.0","font-size:11px;font-weight:700;fill:var(--text,#172033);text-anchor:middle",[763,1461],{"x":1453,"y":1462,"width":774,"height":1454,"rx":766,"fill":769,"stroke":776,"style":777},"68.0",[786,1464,1467],{"x":1457,"y":1465,"style":1466},"87.0","font-size:11px;font-weight:400;fill:var(--text,#172033);text-anchor:middle","1 days 06:00:00",[763,1469],{"x":1453,"y":1470,"width":774,"height":1454,"rx":766,"fill":769,"stroke":776,"style":777},"96.0",[786,1472,1474],{"x":1457,"y":1473,"style":1466},"115.0","0 days 00:30:00",[763,1476],{"x":1477,"y":775,"width":813,"height":1478,"rx":766,"fill":810,"stroke":776,"style":777},"390.6","24.0",[763,1480],{"x":1481,"y":775,"width":1482,"height":1478,"rx":766,"fill":810,"stroke":776,"style":777},"422.6","66.0",[786,1484,1488],{"x":1485,"y":1486,"style":1487},"455.6","57.0","font-size:11px;font-weight:600;fill:var(--muted,#5b6780);text-anchor:middle","A",[763,1490],{"x":1491,"y":775,"width":1492,"height":1478,"rx":766,"fill":810,"stroke":776,"style":777},"488.6","72.4",[786,1494,1496],{"x":1495,"y":1486,"style":1487},"524.8","B",[763,1498],{"x":1499,"y":775,"width":1500,"height":1478,"rx":766,"fill":810,"stroke":776,"style":777},"561.0","64.9",[786,1502,1504],{"x":1503,"y":1486,"style":1487},"593.4","C",[763,1506],{"x":1477,"y":1507,"width":813,"height":1454,"rx":766,"fill":810,"stroke":776,"style":777},"64.0",[786,1509,171],{"x":1510,"y":1511,"style":1487},"406.6","83.0",[763,1513],{"x":1481,"y":1507,"width":1482,"height":1454,"rx":766,"fill":782,"stroke":783,"style":1514},"stroke-width:1.5px",[786,1516,1518],{"x":1485,"y":1511,"style":1517},"font-size:11px;font-weight:700;fill:var(--brand-strong,#4338ca);text-anchor:middle","stored",[763,1520],{"x":1491,"y":1507,"width":1492,"height":1454,"rx":766,"fill":782,"stroke":783,"style":1514},[786,1522,1523],{"x":1495,"y":1511,"style":1517},"format 0",[763,1525],{"x":1499,"y":1507,"width":1500,"height":1454,"rx":766,"fill":782,"stroke":783,"style":1514},[786,1527,1415],{"x":1503,"y":1511,"style":1517},[763,1529],{"x":1477,"y":1530,"width":813,"height":1454,"rx":766,"fill":810,"stroke":776,"style":777},"92.0",[786,1532,177],{"x":1510,"y":845,"style":1487},[763,1534],{"x":1481,"y":1530,"width":1482,"height":1454,"rx":766,"fill":769,"stroke":776,"style":777},[786,1536,1245],{"x":1485,"y":845,"style":1466},[763,1538],{"x":1491,"y":1530,"width":1492,"height":1454,"rx":766,"fill":1539,"stroke":1540,"style":1514},"#fce9e9","var(--danger,#dc2626)",[786,1542,171],{"x":1495,"y":845,"style":1543},"font-size:11px;font-weight:700;fill:var(--accent-ink,#be185d);text-anchor:middle",[763,1545],{"x":1499,"y":1530,"width":1500,"height":1454,"rx":766,"fill":1546,"stroke":1547,"style":1514},"#d9f4f1","var(--teal,#0f9488)",[786,1549,1419],{"x":1503,"y":845,"style":1550},"font-size:11px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:middle",[763,1552],{"x":1477,"y":1553,"width":813,"height":1454,"rx":766,"fill":810,"stroke":776,"style":777},"120.0",[786,1555,453],{"x":1510,"y":1556,"style":1487},"139.0",[763,1558],{"x":1481,"y":1553,"width":1482,"height":1454,"rx":766,"fill":769,"stroke":776,"style":777},[786,1560,1249],{"x":1485,"y":1556,"style":1466},[763,1562],{"x":1491,"y":1553,"width":1492,"height":1454,"rx":766,"fill":1539,"stroke":1540,"style":1514},[786,1564,766],{"x":1495,"y":1556,"style":1543},[763,1566],{"x":1499,"y":1553,"width":1500,"height":1454,"rx":766,"fill":1546,"stroke":1547,"style":1514},[786,1568,1569],{"x":1503,"y":1556,"style":1550},"0:30",[786,1571,1574],{"x":1457,"y":1572,"style":1573},"29.0","font-size:12.5px;font-weight:700;fill:var(--muted,#5b6780);text-anchor:middle","pandas timedelta",[786,1576,1578],{"x":1577,"y":1572,"style":1573},"508.2","cell value \u002F shown with \"0\" \u002F shown with [h]:mm",[49,1580],{"x1":1581,"y1":1582,"x2":1583,"y2":1582,"stroke":783,"style":1584},"262.9","82.0","376.6","stroke-width:2px",[1586,1587],"polygon",{"points":1588,"fill":1589},"380.6,82.0 371.6,87.0 371.6,77.0","#5b5cf0",[763,1591],{"x":1592,"y":1593,"width":1594,"height":1595,"rx":1596,"fill":769,"stroke":776,"style":784},"282.7","49.0","78.2","22.0","11",[786,1598,1601],{"x":1599,"y":1507,"style":1600},"321.8","font-size:11.5px;font-weight:400;fill:var(--brand-strong,#4338ca);text-anchor:middle;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace","to_excel",[33,1603,1605],{"id":1604},"step-5-numbers-that-do-not-survive","Step 5 — Numbers that do not survive",[10,1607,1608,1609,1611,1612,1615,1616,1618,1619,1622,1623,1625,1626,1628,1629,1632,1633,1636],{},"Excel stores every number as a 64-bit float, which holds about 15–16 significant digits. A 17-digit integer such as an order or card-like ID is written rounded — ",[13,1610,467],{}," came back as ",[13,1613,1614],{},"1.234567890123457e+16"," — and nothing on the Excel side can restore it. ",[13,1617,969],{}," values are converted to float on the way in, so ",[13,1620,1621],{},"2.005"," is stored as the nearest binary float, which is fine for display but not for exact accounting comparisons. Infinity is written as the ",[22,1624,786],{}," ",[13,1627,19],{}," (controlled by ",[13,1630,1631],{},"inf_rep","), so a numeric column suddenly contains strings that break ",[13,1634,1635],{},"SUM",". Fix all three before writing:",[38,1638,1640],{"className":85,"code":1639,"language":87,"meta":43,"style":43},"fixed = frame.assign(**{\n    \"17-digit int\": frame[\"17-digit int\"].astype(str),\n    \"Decimal\": frame[\"Decimal\"].map(lambda d: float(round(d, 2))),\n    \"inf\": frame[\"inf\"].replace([np.inf, -np.inf], np.nan),\n})\nfixed[[\"17-digit int\", \"Decimal\", \"inf\"]].to_excel(\"numbers.xlsx\", index=False)\nfor row in load_workbook(\"numbers.xlsx\").active.iter_rows(min_row=2, values_only=True):\n    print(row)\n",[13,1641,1642,1658,1676,1710,1727,1731,1762,1794],{"__ignoreMap":43},[47,1643,1644,1647,1649,1652,1655],{"class":49,"line":50},[47,1645,1646],{"class":98},"fixed ",[47,1648,155],{"class":94},[47,1650,1651],{"class":98}," frame.assign(",[47,1653,1654],{"class":94},"**",[47,1656,1657],{"class":98},"{\n",[47,1659,1660,1662,1665,1668,1671,1674],{"class":49,"line":108},[47,1661,462],{"class":57},[47,1663,1664],{"class":98},": frame[",[47,1666,1667],{"class":57},"\"17-digit int\"",[47,1669,1670],{"class":98},"].astype(",[47,1672,1673],{"class":170},"str",[47,1675,192],{"class":98},[47,1677,1678,1680,1682,1685,1688,1691,1694,1697,1699,1702,1705,1707],{"class":49,"line":116},[47,1679,370],{"class":57},[47,1681,1664],{"class":98},[47,1683,1684],{"class":57},"\"Decimal\"",[47,1686,1687],{"class":98},"].map(",[47,1689,1690],{"class":94},"lambda",[47,1692,1693],{"class":98}," d: ",[47,1695,1696],{"class":170},"float",[47,1698,568],{"class":98},[47,1700,1701],{"class":170},"round",[47,1703,1704],{"class":98},"(d, ",[47,1706,177],{"class":170},[47,1708,1709],{"class":98},"))),\n",[47,1711,1712,1714,1716,1719,1722,1724],{"class":49,"line":129},[47,1713,390],{"class":57},[47,1715,1664],{"class":98},[47,1717,1718],{"class":57},"\"inf\"",[47,1720,1721],{"class":98},"].replace([np.inf, ",[47,1723,396],{"class":94},[47,1725,1726],{"class":98},"np.inf], np.nan),\n",[47,1728,1729],{"class":49,"line":142},[47,1730,1326],{"class":98},[47,1732,1733,1736,1738,1740,1742,1744,1746,1749,1752,1754,1756,1758,1760],{"class":49,"line":149},[47,1734,1735],{"class":98},"fixed[[",[47,1737,1667],{"class":57},[47,1739,174],{"class":98},[47,1741,1684],{"class":57},[47,1743,174],{"class":98},[47,1745,1718],{"class":57},[47,1747,1748],{"class":98},"]].to_excel(",[47,1750,1751],{"class":57},"\"numbers.xlsx\"",[47,1753,174],{"class":98},[47,1755,512],{"class":183},[47,1757,155],{"class":94},[47,1759,249],{"class":170},[47,1761,519],{"class":98},[47,1763,1764,1766,1768,1770,1772,1774,1777,1779,1781,1783,1785,1788,1790,1792],{"class":49,"line":161},[47,1765,618],{"class":94},[47,1767,1334],{"class":98},[47,1769,624],{"class":94},[47,1771,555],{"class":98},[47,1773,1751],{"class":57},[47,1775,1776],{"class":98},").active.iter_rows(",[47,1778,630],{"class":183},[47,1780,155],{"class":94},[47,1782,177],{"class":170},[47,1784,174],{"class":98},[47,1786,1787],{"class":183},"values_only",[47,1789,155],{"class":94},[47,1791,244],{"class":170},[47,1793,646],{"class":98},[47,1795,1796,1798],{"class":49,"line":195},[47,1797,661],{"class":170},[47,1799,1800],{"class":98},"(row)\n",[10,1802,1803,1804,1807,1808,1256,1812,31],{},"Long identifiers are written as text so every digit survives; decimals are rounded to the precision the report needs; infinities become empty cells (or pass ",[13,1805,1806],{},"inf_rep=\"#N\u002FA\""," if you prefer a visible marker). See ",[27,1809,1811],{"href":1810},"\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-long-id-numbers-losing-digits-in-excel\u002F","Fix Long ID Numbers Losing Digits in Excel",[27,1813,1815],{"href":1814},"\u002Fgetting-started-with-python-excel-automation\u002Fwriting-dataframes-to-excel-with-pandas\u002Fcontrol-how-nan-and-infinity-appear-in-excel-output\u002F","Control How NaN and Infinity Appear in Excel Output",[33,1817,1819],{"id":1818},"step-6-objects-that-turn-into-text","Step 6 — Objects that turn into text",[10,1821,1822,1823,1826,1827,1830,1831,1833,1834,1837],{},"Anything pandas cannot map to a number, boolean or date is written with ",[13,1824,1825],{},"str()",": a ",[13,1828,1829],{},"Period"," becomes ",[13,1832,411],{},", a list becomes ",[13,1835,1836],{},"\"[1, 2]\"",", a dict its repr. Categoricals write their labels, which is usually what you want. Convert periods to real dates so Excel can sort and chart them, and join lists into readable text:",[38,1839,1841],{"className":85,"code":1840,"language":87,"meta":43,"style":43},"tidy = pd.DataFrame({\n    \"Month\": frame[\"Period\"].dt.to_timestamp(),\n    \"Items\": frame[\"list\"].map(lambda xs: \", \".join(map(str, xs))),\n})\nwith pd.ExcelWriter(\"tidy.xlsx\", engine=\"xlsxwriter\", datetime_format=\"mmm yyyy\") as xw:\n    tidy.to_excel(xw, index=False)\nws = load_workbook(\"tidy.xlsx\").active\nprint(ws[\"A2\"].value, ws[\"A2\"].number_format, \"|\", ws[\"B2\"].value)\n",[13,1842,1843,1853,1866,1899,1903,1935,1948,1960],{"__ignoreMap":43},[47,1844,1845,1848,1850],{"class":49,"line":50},[47,1846,1847],{"class":98},"tidy ",[47,1849,155],{"class":94},[47,1851,1852],{"class":98}," pd.DataFrame({\n",[47,1854,1855,1858,1860,1863],{"class":49,"line":108},[47,1856,1857],{"class":57},"    \"Month\"",[47,1859,1664],{"class":98},[47,1861,1862],{"class":57},"\"Period\"",[47,1864,1865],{"class":98},"].dt.to_timestamp(),\n",[47,1867,1868,1871,1873,1876,1878,1880,1883,1886,1889,1892,1894,1896],{"class":49,"line":116},[47,1869,1870],{"class":57},"    \"Items\"",[47,1872,1664],{"class":98},[47,1874,1875],{"class":57},"\"list\"",[47,1877,1687],{"class":98},[47,1879,1690],{"class":94},[47,1881,1882],{"class":98}," xs: ",[47,1884,1885],{"class":57},"\", \"",[47,1887,1888],{"class":98},".join(",[47,1890,1891],{"class":170},"map",[47,1893,568],{"class":98},[47,1895,1673],{"class":170},[47,1897,1898],{"class":98},", xs))),\n",[47,1900,1901],{"class":49,"line":129},[47,1902,1326],{"class":98},[47,1904,1905,1907,1909,1912,1914,1916,1918,1920,1922,1924,1926,1929,1931,1933],{"class":49,"line":142},[47,1906,1092],{"class":94},[47,1908,1095],{"class":98},[47,1910,1911],{"class":57},"\"tidy.xlsx\"",[47,1913,174],{"class":98},[47,1915,1103],{"class":183},[47,1917,155],{"class":94},[47,1919,1108],{"class":57},[47,1921,174],{"class":98},[47,1923,1205],{"class":183},[47,1925,155],{"class":94},[47,1927,1928],{"class":57},"\"mmm yyyy\"",[47,1930,1134],{"class":98},[47,1932,102],{"class":94},[47,1934,1139],{"class":98},[47,1936,1937,1940,1942,1944,1946],{"class":49,"line":149},[47,1938,1939],{"class":98},"    tidy.to_excel(xw, ",[47,1941,512],{"class":183},[47,1943,155],{"class":94},[47,1945,249],{"class":170},[47,1947,519],{"class":98},[47,1949,1950,1952,1954,1956,1958],{"class":49,"line":161},[47,1951,550],{"class":98},[47,1953,155],{"class":94},[47,1955,555],{"class":98},[47,1957,1911],{"class":57},[47,1959,560],{"class":98},[47,1961,1962,1964,1966,1968,1971,1973,1975,1977,1979,1981],{"class":49,"line":195},[47,1963,565],{"class":170},[47,1965,1182],{"class":98},[47,1967,1185],{"class":57},[47,1969,1970],{"class":98},"].value, ws[",[47,1972,1185],{"class":57},[47,1974,1188],{"class":98},[47,1976,1191],{"class":57},[47,1978,1194],{"class":98},[47,1980,1197],{"class":57},[47,1982,1983],{"class":98},"].value)\n",[744,1985,753,1990,753,1993,753,1996,753,1999,753,2004,753,2014,753,2020,753,2024,753,2028,753,2033,753,2036,753,2039,753,2045,753,2049,753,2052,753,2055,753,2059,753,2062,753,2067,753,2074,753,2080,753,2084,753,2088,753,2091,753,2094,753,2101,753,2106,753,2109,753,2112,753,2116,753,2119,753,2122,753,2128,753,2131,753,2134],{"viewBox":1986,"role":747,"ariaLabelledBy":1987,"xmlns":751,"style":752},"4 0 752 142",[1988,1989],"dt-prep-t","dt-prep-d",[755,1991,1992],{"id":1988},"A pre-write pass that makes the workbook hold what you meant",[759,1994,1995],{"id":1989},"Four conversions applied before to_excel. Timezone-aware datetimes are converted and made naive, durations become hours or get a duration format, long identifiers become text, and Period and list objects become dates and joined strings.",[763,1997],{"x":765,"y":766,"width":767,"height":1998,"fill":769},"142",[763,2000],{"x":772,"y":773,"width":2001,"height":2002,"rx":2003,"fill":782,"stroke":783,"style":1584},"115.2","110.5","12",[2005,2006,2008],"g",{"transform":2007},"translate(65.6,29.0) scale(1.000)",[2009,2010],"path",{"d":2011,"fill":876,"stroke":2012,"style":2013},"M12 3a9 9 0 1 0 .01 0z M12 7v5l3.5 2","var(--brand-strong,#4338ca)","stroke-width:1.80px;stroke-linecap:round;stroke-linejoin:round",[786,2015,2019],{"x":2016,"y":2017,"style":2018},"77.6","75.5","font-size:13.5px;font-weight:700;fill:var(--brand-strong,#4338ca);text-anchor:middle","Datetimes",[786,2021,2023],{"x":2016,"y":2022,"style":822},"95.0","tz_convert, then",[786,2025,2027],{"x":2016,"y":2026,"style":822},"112.5","tz_localize(None)",[49,2029],{"x1":2030,"y1":2031,"x2":2032,"y2":2031,"stroke":783,"style":1584},"140.2","71.2","162.2",[1586,2034],{"points":2035,"fill":1589},"166.2,71.2 157.2,76.2 157.2,66.2",[763,2037],{"x":2038,"y":773,"width":2001,"height":2002,"rx":2003,"fill":782,"stroke":783,"style":1584},"171.2",[2005,2040,2042],{"transform":2041},"translate(216.8,29.0) scale(1.000)",[2009,2043],{"d":2044,"fill":876,"stroke":2012,"style":2013},"M4 5h16v15H4z M4 10h16 M8 3v4 M16 3v4",[786,2046,2048],{"x":2047,"y":2017,"style":2018},"228.8","Durations",[786,2050,2051],{"x":2047,"y":2022,"style":822},"hours as float,",[786,2053,2054],{"x":2047,"y":2026,"style":822},"or [h]:mm",[49,2056],{"x1":2057,"y1":2031,"x2":2058,"y2":2031,"stroke":783,"style":1584},"291.4","313.4",[1586,2060],{"points":2061,"fill":1589},"317.4,71.2 308.4,76.2 308.4,66.2",[763,2063],{"x":2064,"y":773,"width":2001,"height":2002,"rx":2003,"fill":2065,"stroke":2066,"style":1584},"322.4","#fdefd8","var(--gold,#b4740a)",[2005,2068,2070],{"transform":2069},"translate(368.0,37.8) scale(1.000)",[2009,2071],{"d":2072,"fill":876,"stroke":2073,"style":2013},"M5 9h14 M4 15h14 M10 4l-2 16 M16 4l-2 16","var(--gold-ink,#7a4e06)",[786,2075,2079],{"x":2076,"y":2077,"style":2078},"380.0","84.2","font-size:13.5px;font-weight:700;fill:var(--gold-ink,#7a4e06);text-anchor:middle","Long IDs",[786,2081,2083],{"x":2076,"y":2082,"style":822},"103.8","astype(str)",[49,2085],{"x1":2086,"y1":2031,"x2":2087,"y2":2031,"stroke":783,"style":1584},"442.6","464.6",[1586,2089],{"points":2090,"fill":1589},"468.6,71.2 459.6,76.2 459.6,66.2",[763,2092],{"x":2093,"y":773,"width":2001,"height":2002,"rx":2003,"fill":1546,"stroke":1547,"style":1584},"473.6",[2005,2095,2097],{"transform":2096},"translate(519.2,29.0) scale(1.000)",[2009,2098],{"d":2099,"fill":876,"stroke":2100,"style":2013},"M9 8l-4 4 4 4 M15 8l4 4-4 4","var(--teal-ink,#0b6157)",[786,2102,2105],{"x":2103,"y":2017,"style":2104},"531.2","font-size:13.5px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:middle","Objects",[786,2107,2108],{"x":2103,"y":2022,"style":822},"to_timestamp,",[786,2110,2111],{"x":2103,"y":2026,"style":822},"join lists",[49,2113],{"x1":2114,"y1":2031,"x2":2115,"y2":2031,"stroke":783,"style":1584},"593.8","615.8",[1586,2117],{"points":2118,"fill":1589},"619.8,71.2 610.8,76.2 610.8,66.2",[763,2120],{"x":2121,"y":773,"width":2001,"height":2002,"rx":2003,"fill":1546,"stroke":1547,"style":1584},"624.8",[2005,2123,2125],{"transform":2124},"translate(670.4,29.0) scale(1.000)",[2009,2126],{"d":2127,"fill":876,"stroke":2100,"style":2013},"M6 3h9l4 4v14H6z M15 3v4h4 M9.5 11.5l4.5 6 M14 11.5l-4.5 6",[786,2129,1601],{"x":2130,"y":2017,"style":2104},"682.4",[786,2132,2133],{"x":2130,"y":2022,"style":822},"cells hold real",[786,2135,2136],{"x":2130,"y":2026,"style":822},"values",[33,2138,2140],{"id":2139},"step-7-text-that-changes-meaning-on-the-way-in","Step 7 — Text that changes meaning on the way in",[10,2142,2143,2144,2146,2147,2150,2151,2154],{},"Plain strings are the safest type, with two exceptions worth testing for. A string that starts with ",[13,2145,155],{}," is written as a ",[22,2148,2149],{},"formula"," by both engines — ",[13,2152,2153],{},"\"=1+1\""," arrives as a formula cell, not as text — which is how formula injection gets into exported files. And the xlsxwriter engine turns strings that look like URLs into clickable hyperlinks, while the openpyxl engine leaves them as text:",[38,2156,2158],{"className":85,"code":2157,"language":87,"meta":43,"style":43},"risky = pd.DataFrame({\"s\": [\"=1+1\", \"00123\", \"http:\u002F\u002Fexample.org\", \"1e5\"]})\nfor engine in (\"xlsxwriter\", \"openpyxl\"):\n    risky.to_excel(\"risky.xlsx\", index=False, engine=engine)\n    cells = load_workbook(\"risky.xlsx\").active[\"A\"][1:]\n    print(engine, [(c.value, c.data_type) for c in cells], \"link:\", cells[2].hyperlink is not None)\n",[13,2159,2160,2195,2216,2241,2265],{"__ignoreMap":43},[47,2161,2162,2165,2167,2170,2173,2175,2177,2179,2182,2184,2187,2189,2192],{"class":49,"line":50},[47,2163,2164],{"class":98},"risky ",[47,2166,155],{"class":94},[47,2168,2169],{"class":98}," pd.DataFrame({",[47,2171,2172],{"class":57},"\"s\"",[47,2174,227],{"class":98},[47,2176,2153],{"class":57},[47,2178,174],{"class":98},[47,2180,2181],{"class":57},"\"00123\"",[47,2183,174],{"class":98},[47,2185,2186],{"class":57},"\"http:\u002F\u002Fexample.org\"",[47,2188,174],{"class":98},[47,2190,2191],{"class":57},"\"1e5\"",[47,2193,2194],{"class":98},"]})\n",[47,2196,2197,2199,2202,2204,2207,2209,2211,2214],{"class":49,"line":108},[47,2198,618],{"class":94},[47,2200,2201],{"class":98}," engine ",[47,2203,624],{"class":94},[47,2205,2206],{"class":98}," (",[47,2208,1108],{"class":57},[47,2210,174],{"class":98},[47,2212,2213],{"class":57},"\"openpyxl\"",[47,2215,646],{"class":98},[47,2217,2218,2221,2224,2226,2228,2230,2232,2234,2236,2238],{"class":49,"line":116},[47,2219,2220],{"class":98},"    risky.to_excel(",[47,2222,2223],{"class":57},"\"risky.xlsx\"",[47,2225,174],{"class":98},[47,2227,512],{"class":183},[47,2229,155],{"class":94},[47,2231,249],{"class":170},[47,2233,174],{"class":98},[47,2235,1103],{"class":183},[47,2237,155],{"class":94},[47,2239,2240],{"class":98},"engine)\n",[47,2242,2243,2246,2248,2250,2252,2254,2257,2260,2262],{"class":49,"line":129},[47,2244,2245],{"class":98},"    cells ",[47,2247,155],{"class":94},[47,2249,555],{"class":98},[47,2251,2223],{"class":57},[47,2253,1406],{"class":98},[47,2255,2256],{"class":57},"\"A\"",[47,2258,2259],{"class":98},"][",[47,2261,171],{"class":170},[47,2263,2264],{"class":98},":]\n",[47,2266,2267,2269,2272,2274,2277,2279,2282,2285,2288,2290,2293,2296,2299,2302],{"class":49,"line":142},[47,2268,661],{"class":170},[47,2270,2271],{"class":98},"(engine, [(c.value, c.data_type) ",[47,2273,618],{"class":94},[47,2275,2276],{"class":98}," c ",[47,2278,624],{"class":94},[47,2280,2281],{"class":98}," cells], ",[47,2283,2284],{"class":57},"\"link:\"",[47,2286,2287],{"class":98},", cells[",[47,2289,177],{"class":170},[47,2291,2292],{"class":98},"].hyperlink ",[47,2294,2295],{"class":94},"is",[47,2297,2298],{"class":94}," not",[47,2300,2301],{"class":170}," None",[47,2303,519],{"class":98},[10,2305,2306,2307,2309,2310,2312,2313,1256,2315,2317,2318,174,2320,174,2323,2325,2326,1223,2329,31],{},"Both engines store ",[13,2308,2153],{}," with data type ",[13,2311,571],{},". Numeric-looking text such as ",[13,2314,2181],{},[13,2316,2191],{}," stays text, so leading zeros survive. Neutralise user-supplied values that begin with ",[13,2319,155],{},[13,2321,2322],{},"+",[13,2324,396],{}," or ",[13,2327,2328],{},"@",[27,2330,2332],{"href":2331},"\u002Fautomating-reporting-workflows\u002Ferror-handling-and-logging-in-excel-automation\u002Fprevent-formula-injection-in-excel-exports\u002F","Prevent Formula Injection in Excel Exports",[33,2334,2336],{"id":2335},"common-pitfalls","Common pitfalls",[2338,2339,2340,2354,2369,2375,2384],"ul",{},[2341,2342,2343,2347,2348,2350,2351,2353],"li",{},[2344,2345,2346],"strong",{},"Trusting the display."," A timedelta cell showing ",[13,2349,171],{}," holds ",[13,2352,1245],{},"; check the number format before concluding the data is wrong.",[2341,2355,2356,2361,2362,2364,2365,2368],{},[2344,2357,2358,2359,31],{},"Setting a column format after ",[13,2360,1601],{}," pandas writes a format on each datetime and timedelta cell, which wins over ",[13,2363,1423],{},"; pass formats to ",[13,2366,2367],{},"ExcelWriter"," or rewrite the cells.",[2341,2370,2371,2374],{},[2344,2372,2373],{},"IDs as numbers."," Anything longer than 15 digits, or with leading zeros, must be text before writing.",[2341,2376,2377,2380,2381,2383],{},[2344,2378,2379],{},"Infinity in calculated columns."," Ratios with a zero denominator produce ",[13,2382,19],{},", which is written as text and breaks totals.",[2341,2385,2386,2389,2390,2392],{},[2344,2387,2388],{},"Assuming the engines differ."," For values they behave the same; the difference is which writer options they honour (",[13,2391,1205],{}," only works with xlsxwriter).",[33,2394,2396],{"id":2395},"performance-notes","Performance notes",[10,2398,2399,2400,2403,2404,2407,2408,2410,2411,2413,2414,2416],{},"The conversions above are vectorised and cost far less than writing the file. Avoid per-row ",[13,2401,2402],{},".map"," on large frames where a vectorised alternative exists — ",[13,2405,2406],{},"dt.total_seconds()"," instead of a lambda, ",[13,2409,2083],{}," instead of formatting each value. Object columns of lists or dicts slow ",[13,2412,1601],{}," because each value is converted with ",[13,2415,1825],{}," individually; convert them once beforehand.",[33,2418,2420],{"id":2419},"conclusion","Conclusion",[10,2422,2423,2424,2426,2427,2429,2430,2432,2433,2435],{},"Excel cells hold numbers, text, booleans and errors; pandas maps integers, floats, booleans and strings cleanly, writes datetimes as date serials with a full date-time format, durations as day fractions formatted to hide the fraction, infinity as text, ",[13,2425,969],{}," as float, and unknown objects with ",[13,2428,1825],{},". Long integers lose digits and timezone-aware datetimes fail. A short pre-write pass — formats on the writer, hours or ",[13,2431,1415],{}," for durations, text for long IDs, ",[13,2434,1052],{}," for infinity, real dates for periods — makes the workbook hold exactly what the DataFrame meant.",[33,2437,2439],{"id":2438},"frequently-asked-questions","Frequently asked questions",[10,2441,2442,2445,2446,2449],{},[2344,2443,2444],{},"Why does my timedelta column show whole numbers in Excel?","\npandas writes timedeltas as fractions of a day with the number format 0, which rounds the display. The cell holds 1.25 for 1 day 6 hours; apply a format such as ",[47,2447,2448],{},"h",":mm, or write hours as floats instead.",[10,2451,2452,2455],{},[2344,2453,2454],{},"Why is infinity written as \"inf\" text in Excel?","\nExcel has no infinity value, so to_excel writes the string given by inf_rep, which defaults to \"inf\". Replace infinities with NaN before writing, or pass inf_rep to choose another marker.",[10,2457,2458,2461],{},[2344,2459,2460],{},"Does to_excel keep Decimal precision?","\nNo. Decimal values are converted to Python floats, so they are stored as the nearest binary floating-point number. Round them to the precision you need, or write them as text if exact digits matter.",[10,2463,2464,2467],{},[2344,2465,2466],{},"How do I write timezone-aware datetimes to Excel?","\nConvert them to the time zone the reader expects with dt.tz_convert, then remove the zone with dt.tz_localize(None). Excel has no time zone support, so pandas raises ValueError otherwise.",[33,2469,2471],{"id":2470},"related","Related",[2338,2473,2474,2480,2487,2494],{},[2341,2475,2476,2477,2479],{},"Up one level: ",[27,2478,30],{"href":29}," — to_excel and ExcelWriter in depth.",[2341,2481,2482,2486],{},[27,2483,2485],{"href":2484},"\u002Fgetting-started-with-python-excel-automation\u002Fusing-openpyxl-for-excel-file-manipulation\u002Fhow-openpyxl-stores-python-values-in-cells\u002F","How openpyxl Stores Python Values in Cells"," — the same question one level down.",[2341,2488,2489,2493],{},[27,2490,2492],{"href":2491},"\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-excel-does-not-support-timezones-in-datetimes\u002F","Fix \"Excel does not support datetimes with timezones\" in pandas"," — the full fix for aware timestamps.",[2341,2495,2496,2500],{},[27,2497,2499],{"href":2498},"\u002Fgetting-started-with-python-excel-automation\u002Freading-excel-files-with-pandas\u002Fuse-nullable-dtypes-when-reading-excel-with-pandas\u002F","Use Nullable Data Types When Reading Excel with pandas"," — the reverse trip, keeping types intact on read.",[2502,2503,2504],"style",{},"html pre.shiki code .sMTad, html code.shiki .sMTad{--shiki-default:#6F42C1;--shiki-dark:#FFB757}html pre.shiki code .srMev, html code.shiki .srMev{--shiki-default:#032F62;--shiki-dark:#ADDCFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s-kum, html code.shiki .s-kum{--shiki-default:#D73A49;--shiki-dark:#FF9492}html pre.shiki code .skGVy, html code.shiki .skGVy{--shiki-default:#24292E;--shiki-dark:#F0F3F6}html pre.shiki code .sP0c6, html code.shiki .sP0c6{--shiki-default:#005CC5;--shiki-dark:#91CBFF}html pre.shiki code .sa561, html code.shiki .sa561{--shiki-default:#E36209;--shiki-dark:#FFB757}html pre.shiki code .sSjpA, html code.shiki .sSjpA{--shiki-default:#005CC5;--shiki-dark:#FF9492}",{"title":43,"searchDepth":108,"depth":108,"links":2506},[2507,2508,2509,2510,2511,2512,2513,2514,2515,2516,2517,2518,2519],{"id":35,"depth":108,"text":36},{"id":81,"depth":108,"text":82},{"id":522,"depth":108,"text":523},{"id":1061,"depth":108,"text":1062},{"id":1238,"depth":108,"text":1239},{"id":1604,"depth":108,"text":1605},{"id":1818,"depth":108,"text":1819},{"id":2139,"depth":108,"text":2140},{"id":2335,"depth":108,"text":2336},{"id":2395,"depth":108,"text":2396},{"id":2419,"depth":108,"text":2420},{"id":2438,"depth":108,"text":2439},{"id":2470,"depth":108,"text":2471},"2026-10-02","What to_excel actually stores for each pandas dtype — integers, nullable types, floats, booleans, text, datetime64, date objects, timedeltas, categoricals, Decimal, infinity, Period, lists and timezone-aware timestamps — checked cell by cell with openpyxl, plus the conversions to apply before writing so the workbook holds what you meant.","md",[2524,2526,2528,2530],{"q":2444,"a":2525},"pandas writes timedeltas as fractions of a day with the number format 0, which rounds the display. The cell holds 1.25 for 1 day 6 hours; apply a format such as [h]:mm, or write hours as floats instead.",{"q":2454,"a":2527},"Excel has no infinity value, so to_excel writes the string given by inf_rep, which defaults to \"inf\". Replace infinities with NaN before writing, or pass inf_rep to choose another marker.",{"q":2460,"a":2529},"No. Decimal values are converted to Python floats, so they are stored as the nearest binary floating-point number. Round them to the precision you need, or write them as text if exact digits matter.",{"q":2466,"a":2531},"Convert them to the time zone the reader expects with dt.tz_convert, then remove the zone with dt.tz_localize(None). Excel has no time zone support, so pandas raises ValueError otherwise.","how pandas data types are written to excel cells",null,{"breadcrumb":2535},[2536,2538,2541],{"name":2537,"item":1381},"Home",{"name":2539,"item":2540},"Getting Started with Python Excel Automation","\u002Fgetting-started-with-python-excel-automation\u002F",{"name":2542,"item":29},"Writing DataFrames to Excel with Pandas","\u002Fgetting-started-with-python-excel-automation\u002Fwriting-dataframes-to-excel-with-pandas\u002Fhow-pandas-data-types-are-written-to-excel-cells",{"title":2545,"description":2546},"How pandas dtypes Are Written to Excel with to_excel","Cell-by-cell results of to_excel for every common pandas dtype: datetime formats, timedeltas as days with format 0, inf as text, big integers rounded to 15 digits, Decimal to float, Period and lists as strings, and the fixes for each.","how-pandas-data-types-are-written-to-excel-cells","getting-started-with-python-excel-automation\u002Fwriting-dataframes-to-excel-with-pandas\u002Fhow-pandas-data-types-are-written-to-excel-cells\u002Findex",[2550,2551],"writing-excel","pandas","how-to","-aSkurqeVZ2jV6SXEgpGJOMVL6Mn95lqVzNVdK-ZFUM",[2555,2559],{"title":2556,"path":2557,"stem":2558,"children":-1},"Export a Styled pandas DataFrame to Excel","\u002Fgetting-started-with-python-excel-automation\u002Fwriting-dataframes-to-excel-with-pandas\u002Fexport-a-styled-pandas-dataframe-to-excel","getting-started-with-python-excel-automation\u002Fwriting-dataframes-to-excel-with-pandas\u002Fexport-a-styled-pandas-dataframe-to-excel\u002Findex",{"title":2560,"path":2561,"stem":2562,"children":-1},"openpyxl vs xlsxwriter vs pandas.ExcelWriter","\u002Fgetting-started-with-python-excel-automation\u002Fwriting-dataframes-to-excel-with-pandas\u002Fopenpyxl-vs-xlsxwriter-vs-pandas-excelwriter","getting-started-with-python-excel-automation\u002Fwriting-dataframes-to-excel-with-pandas\u002Fopenpyxl-vs-xlsxwriter-vs-pandas-excelwriter\u002Findex",[2564,2566],{"path":2565,"title":2539},"\u002Fgetting-started-with-python-excel-automation",{"path":2567,"title":2542},"\u002Fgetting-started-with-python-excel-automation\u002Fwriting-dataframes-to-excel-with-pandas",[],[2570,2573,2576,2579,2582,2585],{"path":2571,"title":2572,"kind":2552},"\u002Fautomating-reporting-workflows\u002Fbuilding-multi-sheet-excel-dashboards\u002Fwrite-multiple-dataframes-to-one-excel-file","Write Multiple DataFrames to One Excel File",{"path":2574,"title":2575,"kind":2552},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Fwrite-a-formatted-excel-report-with-xlsxwriter","Write a Formatted Excel Report with xlsxwriter",{"path":2577,"title":2578,"kind":2552},"\u002Fgetting-started-with-python-excel-automation\u002Fusing-openpyxl-for-excel-file-manipulation\u002Ffind-and-replace-text-in-excel-with-openpyxl","Find and Replace Text in Excel with openpyxl",{"path":2580,"title":2581,"kind":2552},"\u002Fgetting-started-with-python-excel-automation\u002Fusing-openpyxl-for-excel-file-manipulation\u002Finsert-and-delete-rows-and-columns-with-openpyxl","Insert and Delete Rows and Columns with openpyxl",{"path":2583,"title":2584,"kind":2552},"\u002Fgetting-started-with-python-excel-automation\u002Fusing-openpyxl-for-excel-file-manipulation\u002Fopenpyxl-append-data-to-existing-excel-sheet","openpyxl: Append Data to an Existing Excel Sheet",{"path":2586,"title":2587,"kind":2552},"\u002Fadvanced-data-transformation-and-cleaning\u002Fcleaning-excel-data-with-pandas\u002Freorder-columns-to-match-a-template-layout-with-pandas","Reorder Columns to Match a Template Layout with pandas",1790972076475]