Skip to main content

A package to automatically standardize dates in Pandas DataFrames.

Project description

df-datefixer

PyPI PyPI Downloads

A lightweight Python library to standardize date columns in Pandas DataFrames. It automatically handles multiple date formats, missing values, problematic entries, multi-column fixing, optional datetime conversion, and more.

Installation

Install via pip:

pip install df-datefixer

Usage

Basic usage:

import pandas as pd
from df_datefixer.fixer import fix_dates

df = pd.DataFrame({
    'event_date': ['2022-01-01', '1/2/2022', 'bad-date', None]
})

fixed_df = fix_dates(df, column="event_date", target_format="%Y-%m-%d", missing_value="0")

print(fixed_df)

Multiple columns, datetime conversion, and custom placeholders:

df = pd.DataFrame({
    'start_date': ['2022-01-01', '1/2/2022', 'bad-date', None],
    'end_date': ['2022-02-01', 'invalid', '03-03-2022', None]
})

fixed_df = fix_dates(df, columns=['start_date', 'end_date'], convert_to_datetime=True, missing_value="NaT")

print(fixed_df)

Important note about datetime conversion:

If you set convert_to_datetime=True with a custom missing_value, your column might be converted to object type instead of datetime, because custom placeholders might not be datetime-compatible. For pure datetime operations, leaving missing_value as "NaT" (default datetime placeholder) is recommended.

Parameters

  • df: A pandas DataFrame
  • column: Column name containing dates (single column)
  • columns: List of column names to fix simultaneously
  • target_format: Desired standardized date format (default is "%Y-%m-%d")
  • missing_value: Replacement for missing/unparsable dates (default is "0")
  • verbose: Print details about problematic dates (default is True)
  • convert_to_datetime: Converts fixed dates to pandas datetime type if True (default is False)
  • inplace: Modifies DataFrame in place if True, else returns a new DataFrame (default is False)

Development

Set up virtual environment

python -m venv venv
source venv/bin/activate  # on macOS/Linux
.\venv\Scripts\activate  # on Windows

Clone repository and install dependencies

git clone https://github.com/kyriaki-mvr/df-datefixer.git
cd df-datefixer
pip install -e .
pip install pytest

Run tests

pytest tests

PyPI

See the package on PyPI - df-datefixer.

License

df-datefixer is licensed under the MIT License. See LICENSE for details.

Contributing

Contributions and issues are welcome! Please open an issue or submit a pull request on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

df_datefixer-1.0.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

df_datefixer-1.0.1-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file df_datefixer-1.0.1.tar.gz.

File metadata

  • Download URL: df_datefixer-1.0.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for df_datefixer-1.0.1.tar.gz
Algorithm Hash digest
SHA256 630cb0f4d6c71d5f461c3d6bcc35e12258e1dc0a10d6a6269c751a8bc52bc104
MD5 c37bd3c176eb13eb315373e2142497dc
BLAKE2b-256 76b9eb292672941b797745b63146aee26c794c193323fecce824d0a9535da15b

See more details on using hashes here.

File details

Details for the file df_datefixer-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: df_datefixer-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for df_datefixer-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0edc8915fea5a41847cce8eb8b4bfb219ababae669406bffc32f6430e7582a0e
MD5 f41945667fcb2eaab0a170b4aee3e96f
BLAKE2b-256 ec74fc0426509797881e163dfa846549e398902b5c9bf27ce9d54e7fee5b69e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page