Skip to content

johanneshk/dateinfer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dateinfer

Python library to infer date format from examples

Table of Contents

Problem Statement

Imagine that you are given a large collection of documents and, as part of the extraction process, extract date information and store it in a normalized format. If the documents follow a single schema, the ideal approach is to craft a date parsing string for the schema. However, if the documents follow different schemas or if the contents are noisy (e.g. date fields were hand-populated), the development can become onerous.

This library makes a "best guess" on the proper date parsing string (datetime.strptime) based on examples in the file.

Installation

The simplest way to install the library is:

$ pip install dateinfer

Usage

>>> import dateinfer
>>> dateinfer.infer(['Mon Jan 13 09:52:52 MST 2014', 'Tue Jan 21 15:30:00 EST 2014'])
'%a %b %d %H:%M:%S %Z %Y'
>>>

Give dateinfer.infer a list of example date strings. infer returns a datetime.strftime/strptime-compliant date format string for its "best guess" of a format string that will correctly parse the majority of the examples.

About

Python library to infer date format from examples

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%