datagouv/csv-detective has 57 GitHub stars and 12 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-14 06:06 UTC. Last push 2026-11-06.
できること
- types (float, int, dates, datetimes, JSON) and more specific (latitude, longitude, geoJSON...)
- Communes, Départements, Régions, Pays
- Codes Communes, Codes Postaux, Codes Departement, ISO Pays
- Codes CSP, Description CSP, SIREN
計測したスター増加
- 24時間
- 0
- 7日間
- 履歴を収集中
- 15日間
- 履歴を収集中
- 1か月
- 履歴を収集中
期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。
概要
Inspection of tabular (csv, xls-like, parquet) files to guess the columns' content
データREADME.md
オリジナルCSV Detective
This is a package to automatically detect column content in tabular files. The script reads either the whole file or the first few rows and performs various checks (regex, casting, comparison with official lists...) to see for each column if it matches with various content types.
Currently supported file types: csv(.gz), xls, xlsx, ods, parquet.
You can also directly feed the URL of a remote file (from data.gouv.fr for instance).
How To?
Install the package
You need to have Python >= 3.11 installed. We recommend using a virtual environment.
pip install csv-detective
Detect some columns
Say you have a tabular file located at file_path. This is how you could use csv_detective:
# Import the csv_detective package
from csv_detective import routine
import os # for this example only
# Replace by your file path
file_path = os.path.join('.', 'tests', 'code_postaux_v201410.csv')
# Open your file and run csv_detective
inspection_results = routine(
file_path, # or file URL
num_rows=-1, # Value -1 will analyze all lines of your file, you can change with the number of lines you wish to analyze
save_results=False, # Default False. If True, it will save result output into the same directory as the analyzed file, using the same name as your file and .json extension
output_profile=True, # Default False. If True, returned dict will contain a property "profile" indicating profile (min, max, mean, tops...) of every column of your csv
output_schema=True, # Default False. If True, returned dict will contain a property "schema" containing basic [tableschema](https://specs.frictionlessdata.io/table-schema/) of your file. This can be used to validate structure of other csv which should match same structure.
tags=["fr"], # Default None. If set as a list of strings, only performs checks related to the specified tags (you can see the available tags with FormatsManager().available_tags())
)
So What Do You Get ?
Output
The program creates a python dictionary with the following information :
{
"encoding": "windows-1252", # Encoding detected
"separator": ";", # Detected CSV separator
"header_row_idx": 0, # Index of the header (aka how many lines to skip to get it)
"headers": [ # Header row
'code commune INSEE', 'nom de la commune', 'code postal', "libellé d'acheminement"
],
"total_lines": 42, # Number of rows (excluding header)
"nb_duplicates": 0, # Number of exact duplicates in rows
"heading_columns": 0, # Number of heading columns
"trailing_columns": 0, # Number of trailing columns
"categorical": ['Code commune'], # Columns that contain less than 25 different values (arbitrary threshold)
"columns": { # Property that conciliate detection from labels and content of a column
"Code commune": {
"python_type": "string",
"format": "code_commune",
"score": 1.0
},
"Date de création": {
"python_type": "date",
"format": "date",
"score": 1.0,
# How to read every value of that column: a column that no single format reads
# is not detected as a date at all. Present on every `date` / `datetime_naive` /
# `datetime_aware` column the inference ran on, and absent everywhere else, so a
# consumer always needs a path without it: parquet columns come typed from the
# file itself, `datetime_rfc822` has a single shape, a custom proportion
# deliberately makes the format tolerant, and an analysis produced before this
# key existed is replayed as is.
# A format without the "csvd:" prefix can be handed to datetime.strptime as it is,
# and reads the same there as through csv-detective. A prefixed one cannot, and has
# to go through `csv_detective.formats.date.parse`: text months (strptime only knows
# the abbreviated ones of the process locale, we know the full and abbreviated ones
# of several languages), optional parts written "[.%f]" for a column whose source
# only prints fractional seconds when they are non-zero, and named time zones, which
# strptime reads then drops, leaving a naive datetime where we return an aware one.
"date_format": "%d/%m/%Y"
},
},
"columns_labels": { # Property that return detection from header columns
"Code commune": {
"python_type": "string",
"format": "code_commune",
"score": 0.5
},
},
"columns_fields": { # Property that return detection from content columns
"Code commune": {
"python_type": "string",
"format": "code_commune",
"score": 1.25
},
},
"profile": {
"column_name": {
"min": 1, # only int and float
"max": 12, # only int and float
"mean": 5, # only int and float
"std": 5, # only int and float
"tops": [ # 10 most frequent values in the column
"xxx",
"yyy",
"..."
],
"nb_distinct": 67, # number of distinct values
"nb_missing_values": 102 # number of empty cells in the column
}
},
"schema": { # TableSchema of the file if `output_schema` was set to `True`
"$schema": "https://frictionlessdata.io/schemas/table-schema.json",
"name": "",
"title": "",
"description": "",
"countryCode": "FR",
"homepage": "",
"path": "https://github.com/datagouv/csv-detective",
"resources": [],
"sources": [
{"title": "Spécification Tableschema", "path": "https://specs.frictionlessdata.io/table-schema"},
{"title": "schema.data.gouv.fr", "path": "https://schema.data.gouv.fr"}
],
"created": "2023-02-10",
"lastModified": "2023-02-10",
"version": "0.0.1",
"contributors": [
{"title": "Table schema bot", "email": "[email protected]", "organisation": "data.gouv.fr", "role": "author"}
],
"fields": [
{
"name": "Code commune",
"description": "Le code INSEE de la commune",
"example": "23150",
"type": "string",
"formatFR": "code_commune",
"constraints": {
"required": False,
"pattern": "^([013-9]\\d|2[AB1-9])\\d{3}$",
}
}
]
}
}
The output slightly differs depending on the file format:
- csv files have
encodingandseparator(andcompressionif relevant) - xls, xlsx, ods files have
engineandsheet_name - parquet only has
engine
You may also set output_df to True, in which case the output is a tuple of two elements:
- the analysis (as described above)
- an iterator of
pd.DataFrames which contain the columns cast with the detected types (which can be used withpd.concator in a loop):
inspection, df_chunks = routine(
file_path=file_path,
num_rows=-1,
output_df=True,
)
cast_df = pd.concat(df_chunks, ignore_index=True)
# if "col1" has been detected as a float, then cast_df["col1"] contains floats
What Formats Can Be Detected
Includes :
- types (float, int, dates, datetimes, JSON) and more specific (latitude, longitude, geoJSON...)
- Communes, Départements, Régions, Pays
- Codes Communes, Codes Postaux, Codes Departement, ISO Pays
- Codes CSP, Description CSP, SIREN
- E-Mails, URLs, Téléphones FR
- Years, Dates, Jours de la Semaine FR
- UUIDs, Mongo ObjectIds
See the complete list here.
Validation
If you have a pre-made analysis of a file, you can check whether another file conforms to the same analysis:
from csv_detective import validate
is_valid, *_ = validate(
file_path,
previous_analysis, # exactly as it came out from the routine function
)
Format detection and scoring
For each column, 3 scores are computed for each format, the higher the score, the more likely the format:
- the field score based on the values contained in the column (0.0 to 1.0).
- the label score based on the header of the column (0.0 to 1.0).
- the overall score, computed as
field_score * (1 + label_score/2)(0.0 to 1.5).
The overall score computation aims to give more weight to the column contents while still leveraging the column header.
limited_output - Select the output mode you want for json report
This option allows you to select the output mode you want to pass. To do so, you have to pass a limited_output argument to the routine function. This variable has two possible values:
limited_outputdefaults toTruewhich means report will contain only detected column formats based on a pre-selected threshold proportion in data. Report result is the standard output (an example can be found above in 'Output' section). Only the format with highest score is present in the output.limited_output=Falsemeans report will contain a full list of all column format possibilities for each input data columns with a value associated which match to the proportion of found column type in data. With this report, user can adjust its rules of detection based on a specific threshold and has a better vision of quality detection for each columns. Results could also be easily transformed into a dataframe (columns types in column / column names in rows) for analysis and test.
Improvement suggestions
- Smarter refactors
- Performances improvements
- Test other ways to load and process data (
pandasalternatives) - Add more and more detection modules...
Related ideas:
- store column names to make a learning model based on column names for (possible pre-screen)
- entity resolution (good luck...)
Why Could This Be of Any Use?
Organisations such as data.gouv.fr aggregate huge amounts of un-normalised data. Performing cross-examination across datasets can be difficult. This tool helps enrich the datasets metadata and facilitate linking them together.
udata-hydra is a crawler that checks, analyzes (using csv-detective) and APIfies all tabular files from data.gouv.fr.
An early version of this analysis of all resources on data.gouv.fr can be found here.
関連プロジェクトを探す
Asabeneh/30-Days-Of-Python
30 Days of Python プログラミングチャレンジは、Python プログラミング言語を 30 日で学ぶためのステップバイステップのガイドです。このチャレンジは 100 日以上かかることもあります。自分のペースで進めてください。こちらの動画も役立つかもしれません: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,715 スターgrafana/grafana
オープンで組み合わせ可能なオブザーバビリティおよびデータ可視化プラットフォームです。Prometheus、Loki、Elasticsearch、InfluxDB、Postgres など、複数のソースからメトリクス、ログ、トレースを可視化できます。
77,894 スターredis/redis
リアルタイムのデータ駆動型アプリケーションを構築する開発者にとって、Redis は最も選ばれ、最速で、機能が最も豊富なキャッシュ、データ構造サーバー、ドキュメントおよびベクトルクエリエンジンです。
77,491 スターapache/superset
Apache Superset は、データ可視化とデータ探索のためのプラットフォームです。
75,522 スター