A library for getting correct datatype from pandas DataFrame
Project description
pandas_datatypes
infer_data_types
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pandas_datatypes-1.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16c59b30000c54aef27f5f5c395869df943279ce0bfa145753df2f8d5dd14ac5 |
|
MD5 | 24e3f27841fca1ff8533b2a50771eefb |
|
BLAKE2b-256 | 569b5262860f34a9ba0988a0159267740cdff0b15fe92c2a109186952c2d165f |