smartcolumns 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
smartcolumns/__init__.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""smartcolumns: detect canonical columns in messy tables.
|
|
2
|
+
|
|
3
|
+
Header names in real-world spreadsheets are inconsistent: "Nom_FR", "NOM FR",
|
|
4
|
+
"Moy Bac", "الاسم الكامل". This module maps such headers to canonical names
|
|
5
|
+
(for example ``name_fr`` or ``score``) using simple keyword matching.
|
|
6
|
+
"""
|
|
7
|
+
import re
|
|
8
|
+
|
|
9
|
+
__version__ = "0.1.0"
|
|
10
|
+
__all__ = ["COLUMN_PATTERNS", "clean_col_name", "detect_columns"]
|
|
11
|
+
|
|
12
|
+
COLUMN_PATTERNS = {
|
|
13
|
+
"student_id": ["nodoss", "numero", "number", "id", "matricule", "code"],
|
|
14
|
+
"name_fr": ["nom_fr", "nom", "name_fr", "full_name_fr", "nom et prenom"],
|
|
15
|
+
"name_ar": ["nom_ar", "الاسم", "الاسم الكامل", "name_ar"],
|
|
16
|
+
"score": ["my bac", "moy bac", "moyenne", "score", "resultat", "note", "mark", "average"],
|
|
17
|
+
"decision": ["decision", "result", "status", "admission"],
|
|
18
|
+
"wilaya_fr": ["wilaya_fr", "wilaya", "state", "region"],
|
|
19
|
+
"wilaya_ar": ["wilaya_ar", "الولاية"],
|
|
20
|
+
"school": ["etablissement", "school", "lycee", "ecole", "institution"],
|
|
21
|
+
"series": ["serie", "filiere", "type", "section", "branch"],
|
|
22
|
+
"birth_date": ["datn", "date naissance", "birth", "birth_date", "dob"],
|
|
23
|
+
"birth_place_fr": ["lieun_fr", "birth_place", "place_fr"],
|
|
24
|
+
"birth_place_ar": ["lieunn_a", "place_ar"],
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def clean_col_name(col):
|
|
29
|
+
"""Lowercase, trim, turn underscores into spaces and collapse whitespace."""
|
|
30
|
+
col = str(col).strip().lower()
|
|
31
|
+
col = col.replace("_", " ")
|
|
32
|
+
col = re.sub(r"\s+", " ", col)
|
|
33
|
+
return col
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def detect_columns(columns):
|
|
37
|
+
"""Map canonical names to the original column names found in ``columns``.
|
|
38
|
+
|
|
39
|
+
Returns a dict such as ``{"name_fr": "Nom_FR", "score": "Moy Bac"}``.
|
|
40
|
+
The first matching column wins for each canonical name.
|
|
41
|
+
"""
|
|
42
|
+
detected = {}
|
|
43
|
+
cleaned = {col: clean_col_name(col) for col in columns}
|
|
44
|
+
for canonical_name, patterns in COLUMN_PATTERNS.items():
|
|
45
|
+
for original_col, cleaned_col in cleaned.items():
|
|
46
|
+
if any(pat in cleaned_col for pat in patterns):
|
|
47
|
+
detected[canonical_name] = original_col
|
|
48
|
+
break
|
|
49
|
+
return detected
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: smartcolumns
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Detect and normalize column names in messy CSV and Excel tables (French, Arabic, English).
|
|
5
|
+
Author: vallomar
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/vallomar/smartcolumns
|
|
8
|
+
Keywords: csv,excel,columns,data-cleaning,arabic,french
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.8
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# smartcolumns
|
|
18
|
+
|
|
19
|
+
Detect and normalize column names in messy CSV and Excel tables. It understands French, Arabic and English headers, for example `Nom_FR`, `Moy Bac` or `الاسم الكامل`.
|
|
20
|
+
|
|
21
|
+
It has no dependencies and works on any list of column names, so you can use it with pandas, csv or openpyxl.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install smartcolumns
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from smartcolumns import detect_columns, clean_col_name
|
|
33
|
+
|
|
34
|
+
detect_columns(["Nom_FR", "Moy Bac", "Decision"])
|
|
35
|
+
# {'name_fr': 'Nom_FR', 'score': 'Moy Bac', 'decision': 'Decision'}
|
|
36
|
+
|
|
37
|
+
clean_col_name(" Nom_FR ")
|
|
38
|
+
# 'nom fr'
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
With pandas:
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
import pandas as pd
|
|
45
|
+
from smartcolumns import detect_columns
|
|
46
|
+
|
|
47
|
+
df = pd.read_csv("results.csv")
|
|
48
|
+
cols = detect_columns(df.columns)
|
|
49
|
+
df = df.rename(columns={v: k for k, v in cols.items()})
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Canonical names
|
|
53
|
+
|
|
54
|
+
`student_id`, `name_fr`, `name_ar`, `score`, `decision`, `wilaya_fr`, `wilaya_ar`, `school`, `series`, `birth_date`, `birth_place_fr`, `birth_place_ar`. The keyword lists are in `smartcolumns.COLUMN_PATTERNS`.
|
|
55
|
+
|
|
56
|
+
Matching is by keyword: the first column whose cleaned name contains a keyword wins. Short keywords like `id` can match inside longer names, so check the result on unusual files.
|
|
57
|
+
|
|
58
|
+
## Tests
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
python -m unittest discover tests
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
MIT, see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
smartcolumns/__init__.py,sha256=SLZ-v5TGMBiSOKBRT7IvjAXk8RXqSdd_n4Q8KFETcos,2084
|
|
2
|
+
smartcolumns-0.1.0.dist-info/licenses/LICENSE,sha256=3IUJA4Xgcgi9QZeaWhguVFLc0qui2XPj7HjRgv8PIrg,1065
|
|
3
|
+
smartcolumns-0.1.0.dist-info/METADATA,sha256=kHlT1B1UyTueJQaisG9FDMDzNsnant-TaC3woaUErDY,1877
|
|
4
|
+
smartcolumns-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
5
|
+
smartcolumns-0.1.0.dist-info/top_level.txt,sha256=o3qr8IVqsSpasnT47u7yY1XfiBQlp_WKWl7OABg27Gc,13
|
|
6
|
+
smartcolumns-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 vallomar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
smartcolumns
|