Skip to main content

A library for getting correct datatype from pandas DataFrame

Project description

pandas_datatypes

infer_data_types

GitHub GitHub release (latest by date)

A Python function for inferring data types of columns in a pandas DataFrame.

Overview

infer_data_types is a utility function designed to assist in the process of inferring data types of columns within a pandas DataFrame. It offers functionality to handle numeric columns with NaN values by optionally filling them with zeros, and it can automatically convert columns to datetime objects where appropriate.

Usage

import pandas as pd
import pandas_datatypes 

# Create a DataFrame
data = {
    'A': [1, 2, 3],
    'B': ['2022-01-01', '2022-02-01', '2022-03-01'],
    'C': [4.0, None, 6.0],
}

df = pd.DataFrame(data)

# Infer data types
data_types = pandas_datatypes.infer_data_types(df)

print(data_types)

Function Description

def infer_data_types(df: pd.DataFrame, fill_numeric_zeros: bool = True) -> dict:
Infer data types of columns in a DataFrame.

Args:
    df (pd.DataFrame): Input DataFrame.
    fill_numeric_zeros (bool, optional): Whether to fill NaN values in numeric columns with zeros. Defaults to True.

Returns:
    dict: Dictionary containing column names as keys and inferred data types as values.

df: Input DataFrame for which data types are to be inferred.

fill_numeric_zeros: Optional boolean parameter to indicate whether to fill NaN values in numeric columns with zeros. Defaults to True.

Returns a dictionary containing column names as keys and inferred data types as values.

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

pandas_datatypes-1.2.0.tar.gz (2.3 kB view details)

Uploaded Source

Built Distribution

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

pandas_datatypes-1.2.0-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

Details for the file pandas_datatypes-1.2.0.tar.gz.

File metadata

  • Download URL: pandas_datatypes-1.2.0.tar.gz
  • Upload date:
  • Size: 2.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for pandas_datatypes-1.2.0.tar.gz
Algorithm Hash digest
SHA256 fc10a433983ab43609005a44a641371f537e545370ed18569bbc74e2093cb24c
MD5 fac5805ba3c5f1ed99322a25f3105329
BLAKE2b-256 9163f52f8cc710f0e38a654898d5be9a615a106ec8c30a51dfbc3a9eaa09c61b

See more details on using hashes here.

File details

Details for the file pandas_datatypes-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pandas_datatypes-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 16c59b30000c54aef27f5f5c395869df943279ce0bfa145753df2f8d5dd14ac5
MD5 24e3f27841fca1ff8533b2a50771eefb
BLAKE2b-256 569b5262860f34a9ba0988a0159267740cdff0b15fe92c2a109186952c2d165f

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