This Python script automatically extract (Number, Rank, Name) from multiple Word docs and categorises them into the appropriate category.
It is designed to handle variations in document formatting, including different list styles (numbered, bulleted, symbols like '👉'), minor header variations, and common invisible characters sometimes found in copied text.
Finally, it generates into 2 Excel sheet:
Output_1.xlsx: Contains all extracted unique names with their assigned category, unit category (derived from the filename), and a sequential number (BIL) across the entire dataset.Output_sorted.xlsx: Contains the same personnel data, but sorted alphabetically by category, with a sequential count (COUNT) restarting for each category.
- Processes multiple docx - Simply add them to
input_docsfolder . - Fast and accurate - Uses two method
startwithand check for keywords - Easily configurable - Add more categories under
SECTION_MAP - Cleans input text with multiple methods to ensure output are easily readable
- Assigns unique names to "NEW CHECK" category for manual review if unknown category
- Python 3.x
pandaslibrarypython-docxlibraryopenpyxllibrary
-
Download repo as a zip file and extract
-
Install Libraries:
pip install pandas python-docx openpyxl
-
Place all the
.docxfiles you want to process inside theinput_docsfolder. Script assumes filename (without extension). ExampleBLACKOPS.docx-> UNIT 'BLACKOPS' -
Run the Script:
python arr.py
-
Check Output:
- Two Excel files will be created in the same directory as the script:
Output_1.xlsxOutput_sorted.xlsx
- Review any entries assigned to the
NEW CHECKcategory to see if new headers need to be added to theSECTION_MAP.
- Two Excel files will be created in the same directory as the script:
-
Customization (Optional):
- Modify the
INPUT_FOLDER,OUTPUT_FILE,OUTPUT_SORTED_FILE, andNEW_CATEGORY_LABELconstants if needed. - Edit the
SECTION_MAPdictionary within the script to add, remove, or modify header keywords and their corresponding category mappings. Remember that the order matters for the matching logic – place more specific keywords before more general ones.
- Modify the
- Multi-line Entries: The script processes documents paragraph by paragraph. Personnel names or other data split across multiple lines might not be parsed correctly.
- Complex Layouts: Does not handle data within tables, text boxes, or complex document structures other than standard paragraphs.
- Header Ambiguity: Relies heavily on the keywords and order defined in
SECTION_MAP. Ambiguous headers or very short keywords might occasionally lead to miscategorisation, although the matching logic attempts to mitigate this. Entries underNEW CHECKrequire manual verification.
Released under the MIT License.