Skip to main content

A comprehensive data preprocessing library for data engineering tasks

Project description

My Data Preprocessor

A comprehensive Python library for data preprocessing tasks, designed for data engineering projects.

Installation

Use the package manager pip to install My Data Preprocessor.

pip install my_data_preprocessor_mz

Usage

For CategoricalEncoder

from my_data_preprocessor_mz.categorical_encoder import CategoricalEncoder
import pandas as pd

df = pd.DataFrame({'Genre': ['Action', 'Comedy', 'Drama', 'Action']})

one_hot_encode_df = CategoricalEncoder.one_hot_encode(df, columns=['Genre'])
print("DataFrame after one-hot encoding:\n",one_hot_encode_df)

label_encoded_df = CategoricalEncoder.label_encode(df_movies, columns=['Genre'])
print("\nDataFrame after label encoding:\n", label_encoded_df)

For DataTypeConverter

from my_data_preprocessor_mz.data_type_converter import DataFrameConverter
import pandas as pd

data = {
    'A': ['1', '2', '3', '4'],
    'B': ['5', '6', '7', '8'],
    'C': ['9', '10', '11', '12']
}
df = pd.DataFrame(data)

converter = DataFrameConverter(df)

converter.convert_to_numeric(columns=['A', 'B'])

converter.convert_to_categorical(columns=['C'])

print(converter.df)

For DateTimeHandler

from my_data_preprocessor_mz.datetime_handler import DateTimeManipulator
import pandas as pd

data = {
    'Release Date': ['03/03/2019', '15/06/2020', '23/09/2021', '07/12/2018']
}
df = pd.DataFrame(data)


df_converted = DateTimeManipulator.convert_to_datetime(df, columns=['Release Date'])
print("DataFrame after converting to datetime:")
print(df_converted)

df_date_info = DateTimeManipulator.extract_date_info(df_converted, column='Release Date')
print("\nDataFrame with extracted date information:")
print(df_date_info)

For MissingValueHandler

from my_data_preprocessor_mz.missing_value_handler import Imputer
import pandas as pd
import numpy as np

data = {
    'A': [1, 2, np.nan, 4, 5],
    'B': [np.nan, 2, 3, 4, np.nan],
    'C': ['cat', 'dog', 'cat', np.nan, 'dog']
}
df = pd.DataFrame(data)

imputer = Imputer()

df_mean_imputed = imputer.impute_missing_values(df.copy(), strategy='mean')
print("DataFrame after mean imputation:")
print(df_mean_imputed)

df_median_imputed = imputer.impute_missing_values(df.copy(), strategy='median')
print("\nDataFrame after median imputation:")
print(df_median_imputed)

df_constant_imputed = imputer.impute_missing_values(df.copy(), strategy='constant', constant_value=0)
print("\nDataFrame after constant imputation:")
print(df_constant_imputed)

df_deleted = imputer.impute_missing_values(df.copy(), strategy='delete')
print("\nDataFrame after deleting missing values:")
print(df_deleted)

For OutlierHandler

from my_data_preprocessor_mz.outlier_handler import OutlierHandler
import pandas as pd
import numpy as np

data = {
    'A': [1, 2, 100, 4, 5, 6, 120, 8, 9, 10],
    'B': [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
}
df = pd.DataFrame(data)

outlier_handler = OutlierHandler(df)

outliers_rows, outliers_columns = outlier_handler.identify_and_correct_outliers(column='A', threshold=1.5)

print("DataFrame after handling outliers:")
print(outlier_handler.df)

print("\nOutlier rows and columns:")
print(outliers_rows, outliers_columns)

For Scaler

from my_data_preprocessor_mz.scaler import DataScaler
import pandas as pd

data = {
    'A': [1, 2, 3, 4, 5],
    'B': [10, 20, 30, 40, 50],
    'C': ['a', 'b', 'c', 'd', 'e']  # Non-numeric column to demonstrate error handling
}
df = pd.DataFrame(data)

scaler = DataScaler()

df_standardized = scaler.standardize_data(df.copy(), columns=['A', 'B'])
print("DataFrame after standardization:")
print(df_standardized)

df_normalized = scaler.normalize_data(df.copy(), columns=['A', 'B'])
print("\nDataFrame after normalization:")
print(df_normalized)

For TextCleaner

from my_data_preprocessor_mz.text_cleaner import TextCleaner

text = ("Hello world! This is a test sentence for the TextCleaner class. It's designed to remove stopwords, "
        "punctuation, and to perform lemmatization.")

cleaner = TextCleaner()

lowercase_text = cleaner.to_lowercase(text)
print("Lowercase text:")
print(lowercase_text)

no_punctuation_text = cleaner.remove_punctuation(lowercase_text)
print("\nText without punctuation:")
print(no_punctuation_text)

no_stopwords_text = cleaner.remove_stopwords(no_punctuation_text)
print("\nText without stopwords:")
print(no_stopwords_text)

lemmatized_text = cleaner.lemmatize_text(no_stopwords_text)
print("\nLemmatized text:")
print(lemmatized_text)

cleaned_text = cleaner.clean_text(text)
print("\nFully cleaned text:")
print(cleaned_text)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

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

my_data_preprocessor_mz-0.2.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

my_data_preprocessor_mz-0.2.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file my_data_preprocessor_mz-0.2.0.tar.gz.

File metadata

  • Download URL: my_data_preprocessor_mz-0.2.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for my_data_preprocessor_mz-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c544469b7e18164b16c3fbdf8786255cea92acba8aa180e4a5f4a15a11513466
MD5 cd0070066c706b447e2dc9814a661b5c
BLAKE2b-256 0903fcf4c069db7011f27019632248976d2551c2cd950cba39ec3371669f4b7f

See more details on using hashes here.

File details

Details for the file my_data_preprocessor_mz-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for my_data_preprocessor_mz-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f99a43711a1cd8d2897fe0d0d985072e0d89e290ec8e264efa92a6403284d5e2
MD5 2bd9d680b4e13be6aa6bbf7397ac3aec
BLAKE2b-256 8a0b324ef08736ca8f56d47c08c5dec7745ac06791ef49d0f6c23d903293cc54

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