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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

Supported by

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