[{"data":1,"prerenderedAt":140},["ShallowReactive",2],{"topic:messy-sheets":3},[4,13,20,26,31,37,43,48,54,59,64,70,75,80,85,90,95,101,107,113,119,124,130,135],{"path":5,"title":6,"description":7,"type":8,"topics":9,"kind":12},"\u002Fadvanced-data-transformation-and-cleaning\u002Fextracting-data-from-messy-excel-sheets","Extracting Data from Messy Excel Sheets","Get clean tables out of worksheets built for people: shifting banners, several tables per sheet, two-row headers, subtotal rows, hidden rows and status colours — with pandas and openpyxl.","guide",[10,11],"messy-sheets","reading-excel",null,{"path":14,"title":15,"description":16,"type":17,"topics":18,"kind":12},"\u002Fadvanced-data-transformation-and-cleaning\u002Fextracting-data-from-messy-excel-sheets\u002Fcombine-sheets-with-different-layouts-into-one-table","Combine Sheets with Different Layouts into One Table","Stack sheets that hold the same kind of data in different layouts — headers on different rows, columns in a different order and under different names, extra columns, total rows — into one clean table with pandas: find each sheet's header row, map column synonyms to standard names, drop totals and notes, record the source, and report columns that could not be mapped instead of losing them.","how-to",[10,19],"sheets-and-files",{"path":21,"title":22,"description":23,"type":17,"topics":24,"kind":12},"\u002Fadvanced-data-transformation-and-cleaning\u002Fextracting-data-from-messy-excel-sheets\u002Fextract-hyperlink-urls-from-excel-cells","Extract Hyperlink URLs from Excel Cells with openpyxl","pandas reads the text a link displays, never the address behind it. Get the URLs out of Excel cells with openpyxl — inserted links, mailto links, links to other sheets and HYPERLINK formulas — and handle workbooks too large for normal mode.",[10,11,25],"openpyxl",{"path":27,"title":28,"description":29,"type":17,"topics":30,"kind":12},"\u002Fadvanced-data-transformation-and-cleaning\u002Fextracting-data-from-messy-excel-sheets\u002Fextract-report-header-fields-from-an-excel-sheet","Extract Report Header Fields from an Excel Sheet with Python","Many exported reports put the branch, period, currency and run date in label-value pairs above the table. Read those fields with openpyxl wherever they sit, find where the table starts, parse the period into real dates and attach the fields to every row before combining files.",[10,11,25],{"path":32,"title":33,"description":34,"type":17,"topics":35,"kind":12},"\u002Fadvanced-data-transformation-and-cleaning\u002Fextracting-data-from-messy-excel-sheets\u002Ffind-the-header-row-in-an-excel-sheet-with-a-shifting-layout","Find the Header Row in an Excel Sheet with a Shifting Layout","Exports that start their table on row 3 one month and row 6 the next break skiprows. Scan for the row that holds your required labels, then read from there — with aliases and column offsets handled.",[10,11,36],"pandas",{"path":38,"title":39,"description":40,"type":17,"topics":41,"kind":12},"\u002Fadvanced-data-transformation-and-cleaning\u002Fextracting-data-from-messy-excel-sheets\u002Fparse-numbers-with-units-in-excel-cells","Parse Numbers with Units in Excel Cells","Turn cells like \"12 kg\", \"1,200 g\", \"2.5t\", \"500 ml\", \"3.5k\" and \"1,5 kg\" into numbers in one unit with pandas: a regular expression that splits value from unit, a conversion table for the units you expect, suffixes such as k and M, decimal commas, the pint library for broader unit support, and a report of every value that could not be parsed.",[10,42],"data-cleaning",{"path":44,"title":45,"description":46,"type":17,"topics":47,"kind":12},"\u002Fadvanced-data-transformation-and-cleaning\u002Fextracting-data-from-messy-excel-sheets\u002Fparse-records-that-span-multiple-rows-in-excel","Parse Records That Span Multiple Rows in Excel with pandas","Bank statements wrap long descriptions onto extra rows, and contact exports stack one field per row. Number each record from the row that starts it, join the continuation lines, pivot stacked fields into columns, and catch orphan lines and repeated fields instead of silently mixing records.",[10,42,36],{"path":49,"title":50,"description":51,"type":17,"topics":52,"kind":12},"\u002Fadvanced-data-transformation-and-cleaning\u002Fextracting-data-from-messy-excel-sheets\u002Fread-a-calendar-style-sheet-into-a-table","Read a Calendar-Style Sheet into a Table","Rota planners, booking sheets and leave trackers are often laid out as calendars: a month title, weekday columns, a row of day numbers and a row of entries under each. Turn such grids into one row per date with openpyxl and pandas: find each month block, pair day numbers with their entries, build real dates, skip the padding days from neighbouring months, and validate that every day of every month was read.",[10,53],"dates-and-times",{"path":55,"title":56,"description":57,"type":17,"topics":58,"kind":12},"\u002Fadvanced-data-transformation-and-cleaning\u002Fextracting-data-from-messy-excel-sheets\u002Fread-a-sheet-where-records-run-across-columns","Read an Excel Sheet Where Records Run Across Columns","Some sheets are laid out sideways: field names down column A and one record per column — supplier comparisons, product spec sheets, quotes side by side. Read them with header=None and index_col=0, transpose, fix the column types that transposing mixes up, handle several blocks on one sheet, and write the tidy table back.",[10,11,36],{"path":60,"title":61,"description":62,"type":17,"topics":63,"kind":12},"\u002Fadvanced-data-transformation-and-cleaning\u002Fextracting-data-from-messy-excel-sheets\u002Fread-cell-colours-and-font-styles-as-data-with-openpyxl","Read Cell Colours and Font Styles as Data with openpyxl","When a spreadsheet uses green for done and red for blocked, the colour is the data. Read fill colours, bold and strikethrough with openpyxl and turn them into real columns.",[10,11,25],{"path":65,"title":66,"description":67,"type":17,"topics":68,"kind":12},"\u002Fadvanced-data-transformation-and-cleaning\u002Fextracting-data-from-messy-excel-sheets\u002Fread-dropdown-lists-from-an-existing-workbook","Read Dropdown Lists and Validation Rules from an Existing Workbook","Find out what a template's dropdowns allow — the regions, statuses and priority codes behind each data validation rule — and check the data people entered against them. Read validation rules with openpyxl, resolve inline lists, range references and named ranges to real values, and report every cell that breaks its rule.",[10,69,25],"data-validation",{"path":71,"title":72,"description":73,"type":17,"topics":74,"kind":12},"\u002Fadvanced-data-transformation-and-cleaning\u002Fextracting-data-from-messy-excel-sheets\u002Fread-excel-with-multi-row-headers-in-pandas","Read Excel with Multi-Row Headers in pandas","Load a sheet whose column headers span two rows — a merged quarter above Revenue and Units — into a MultiIndex, then select, flatten or reshape it into a tidy table.",[10,11,36],{"path":76,"title":77,"description":78,"type":17,"topics":79,"kind":12},"\u002Fadvanced-data-transformation-and-cleaning\u002Fextracting-data-from-messy-excel-sheets\u002Fread-multiple-tables-from-one-excel-sheet","Read Multiple Tables from One Excel Sheet","Pull several stacked or side-by-side tables out of a single worksheet with pandas: split on blank rows and columns, find blocks by their header label, or read named Excel tables.",[10,11],{"path":81,"title":82,"description":83,"type":17,"topics":84,"kind":12},"\u002Fadvanced-data-transformation-and-cleaning\u002Fextracting-data-from-messy-excel-sheets\u002Fremove-subtotal-and-total-rows-from-an-excel-export","Remove Subtotal and Total Rows from an Excel Export","Subtotal and grand-total rows double every sum you compute. Find them by label, by missing detail fields or by SUBTOTAL formulas, remove them, and use the totals to check your own numbers.",[10,42,36],{"path":86,"title":87,"description":88,"type":17,"topics":89,"kind":12},"\u002Fadvanced-data-transformation-and-cleaning\u002Fextracting-data-from-messy-excel-sheets\u002Fskip-hidden-and-filtered-rows-when-reading-excel","Skip Hidden and Filtered Rows When Reading Excel","pandas reads every row, including the ones hidden by a filter or collapsed in a group. Use openpyxl to find hidden rows, columns and sheets, and read only what the user can see.",[10,11,25],{"path":91,"title":92,"description":93,"type":17,"topics":94,"kind":12},"\u002Fadvanced-data-transformation-and-cleaning\u002Fextracting-data-from-messy-excel-sheets\u002Fstop-reading-at-notes-and-footers-below-the-data","Stop Reading at Notes and Footers Below the Data","Many Excel reports put a total row, a blank line and footnotes such as \"Source:\" or \"* provisional\" under the table, and pandas reads them all as data. Find where the table really ends — the first blank row, the first row whose key does not look like a key, or a footer marker — read exactly that many rows, keep the footnotes as metadata, and turn footnote markers inside cells into a flag column.",[10,11],{"path":96,"title":97,"description":98,"type":17,"topics":99,"kind":12},"\u002Fadvanced-data-transformation-and-cleaning\u002Fextracting-data-from-messy-excel-sheets\u002Fturn-a-pivot-table-export-back-into-tidy-data","Turn a Pivot Table Export Back into Tidy Data","Someone sends a copy-pasted pivot table instead of the data behind it. Rebuild one row per observation with pandas: combine the two header rows into year and quarter, forward-fill the row labels that pivot layouts leave blank, drop subtotal and grand-total rows, unpivot the value columns, convert the numbers, and prove the result by recomputing the totals the export showed.",[10,100],"pivots-and-summaries",{"path":102,"title":103,"description":104,"type":17,"topics":105,"kind":12},"\u002Fadvanced-data-transformation-and-cleaning\u002Fhandling-missing-data-in-excel-reports\u002Fforward-fill-blank-cells-in-grouped-excel-reports","Forward-Fill Blank Cells in Grouped Excel Reports with pandas","Grouped Excel reports show each region or category once and leave the rows below it blank, often in merged cells. Fill those labels down with pandas without leaking a label into the next group, filling data columns by mistake, or carrying labels into total rows.",[106,10,36],"missing-data",{"path":108,"title":109,"description":110,"type":17,"topics":111,"kind":12},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fstyling-excel-cells-with-openpyxl\u002Ffreeze-header-row-in-excel-with-openpyxl","Freeze the Header Row in Excel with openpyxl","Freeze the header row in Excel from Python with openpyxl using ws.freeze_panes. Freeze rows, columns, or both, understand the anchor cell, and unfreeze — runnable.",[10,112,25],"cell-styling",{"path":114,"title":115,"description":116,"type":17,"topics":117,"kind":12},"\u002Fgetting-started-with-python-excel-automation\u002Fhandling-excel-file-formats-and-conversions\u002Fextract-tables-from-a-pdf-into-excel-with-python","Extract Tables from a PDF into Excel with Python","Get tables out of PDF statements and reports and into a workbook with pdfplumber and pandas: ruled tables that span several pages, repeated header rows, amounts with thousands separators, day-first dates, borderless tables rebuilt from word positions, a control-total check and a formatted .xlsx.",[118,10],"file-formats",{"path":120,"title":121,"description":122,"type":17,"topics":123,"kind":12},"\u002Fgetting-started-with-python-excel-automation\u002Freading-excel-files-with-pandas\u002Fhandle-merged-cells-when-reading-excel-with-pandas","Handle Merged Cells When Reading Excel with pandas","Merged cells read as one value and a run of blanks. Fix them in pandas with forward fill, detect merges with openpyxl, and unmerge a workbook before importing it.",[10,11,36],{"path":125,"title":126,"description":127,"type":17,"topics":128,"kind":12},"\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-mergedcell-value-is-read-only-in-openpyxl","Fix \"MergedCell object attribute value is read-only\" in openpyxl","openpyxl raises this AttributeError when code writes to a cell that sits inside a merged range. Find the merge, write to its top-left cell, and watch for the less obvious cause — insert_rows and delete_rows move cells but leave merged ranges behind.",[129,25,10],"troubleshooting",{"path":131,"title":132,"description":133,"type":17,"topics":134,"kind":12},"\u002Fgetting-started-with-python-excel-automation\u002Fusing-openpyxl-for-excel-file-manipulation\u002Ftranspose-a-range-of-cells-with-openpyxl","Transpose a Range of Cells with openpyxl","Swap rows and columns in a worksheet from Python: transpose values with zip, carry fonts, fills, borders and number formats across, handle merged cells and column widths, transpose with pandas when styles do not matter, and write a live TRANSPOSE array formula instead of a copy.",[25,10],{"path":136,"title":137,"description":138,"type":17,"topics":139,"kind":12},"\u002Fgetting-started-with-python-excel-automation\u002Fusing-openpyxl-for-excel-file-manipulation\u002Funmerge-cells-and-fill-values-with-openpyxl","Unmerge Cells and Fill the Values with openpyxl","Turn merged cells into a proper table — find every merged range, unmerge it, copy the top-left value into each cell, keep the formatting, and handle the read-only and pandas cases where merge information is missing.",[10,25],1790972052271]