Various utilities for IBIS applications in data science and engineering
Project description
i38e-utils
i38e-utils is a collection of utility functions and classes that I use in my projects. It is a work in progress and will be updated as I add more functionality.
Currently, it includes the following:
- DfHelper: A class designed to facilitate data handling and operations within a Django project, particularly focusing on loading data from both parquet files and a database, and potentially saving data to parquet format.
- GeoPyHelper: A class that provides a set of utility functions for working with GeoPy.
- OsmxHelper: A class that provides a set of utility functions for working with Osmnx.
- data_utils: A set of utility functions/classes for working with data.
- date_utils: A set of utility functions for working with dates.
- df_utils: A set of utility functions for working with pandas DataFrames.
- file_utils: A set of utility functions for working with files.
- log_utils: A set of utility functions for working with logs.
Installation
To install this project, follow these steps:
pip install i38e-utils
Usage
DfHelper: Dataframe Helper Class
Scenarios:
- Connect to a database table using a Django's ORM connection, query, transform and convert the data to a pandas DataFrame.
import pandas as pd
import numpy as np
from i38e_utils.df_helper import DfHelper
phone_mobile_gps_fields = {
'id_tracking': 'id',
'id_producto': 'product_id',
'pk_empleado': 'associate_id',
'latitud': 'latitude',
'longitud': 'longitude',
'fecha_hora_servidor': 'server_dt',
'fecha_hora': 'date_time',
'accion': 'action',
'descripcion': 'description',
'imei': 'imei'
}
class GpsCube(DfHelper):
df: pd.DataFrame = None
live: bool = False
save_parquet = True
config={
'connection_name': 'replica',
'table': 'asm_tracking_movil_gps',
'field_map': phone_mobile_gps_fields,
'legacy_filters': True,
}
def __init__(self, **opts):
config = {**self.config, **opts}
super().__init__(**config)
def load(self, **kwargs):
self.df = super().load(**kwargs)
self.fix_data()
return self.df
def fix_data(self):
self.df['latitude'] = self.df['latitude'].astype(np.float64)
self.df['longitude'] = self.df['longitude'].astype(np.float64)```python
gps_cube=GpsCube(live=True, debug=False)
df=gps_cube.load(date_time__date='2023-03-04')
# to save to a parquet file
gps_cube.save_to_parquet(df, parquet_full_path='gpscube.parquet')
- Use a parquet storage file or folder structure to load data and perform some transformations.
import pandas as pd
from i38e_utils.df_helper import DfHelper
class GpsParquetCube(DfHelper):
df: pd.DataFrame = None
config={
'use_parquet': True,
'df_as_dask': True,
'parquet_storage_path': '/storage/data/parquet/gps',
'parquet_start_date': '2024-01-01',
'parquet_end_date': '2024-03-31',
}
def __init__(self, **opts):
config = {**self.config, **opts}
super().__init__(**config)
def load(self, **kwargs):
self.df = super().load(**kwargs)
return self.df
# The following example would load all the parquet files in the folder structure described in parquet_storage_path matching the date range and return a single dask dataframe for associate_id 27 for the month of March.
# The class converts Django style filters to dask compatible filters.
# The class also converts the parquet files to a dask dataframe for faster processing.
params = {
'associate_id': 27,
'date_time__date__range': ['2024-03-01','2024-03-31']
}
dask_df = GpsParquetCube().load(**params)
# to convert to a pandas dataframe
df = dask_df.compute()
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file i38e_utils-1.0.30.tar.gz.
File metadata
- Download URL: i38e_utils-1.0.30.tar.gz
- Upload date:
- Size: 26.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.11.2 Darwin/23.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
146b79a4cdc041996af121611ccbfb93888bdc2209ea1e024f3aadecde6a8f7b
|
|
| MD5 |
c92e1155017920f2d1cfed1d243c48cd
|
|
| BLAKE2b-256 |
20ba68cc03bb5e16fdeef4d7657b29bf55925d933c1859e01a974de0546be539
|
File details
Details for the file i38e_utils-1.0.30-py3-none-any.whl.
File metadata
- Download URL: i38e_utils-1.0.30-py3-none-any.whl
- Upload date:
- Size: 30.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.11.2 Darwin/23.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10e2702a81cc503976c506a2c89648c55dba683298a6f3755c3f8a7564f29e96
|
|
| MD5 |
a89b68c744955c1549086fe7e9b0e7bf
|
|
| BLAKE2b-256 |
dbfa393880a6534c6bbee1aa72deb3ff285721c77faa778b4a48221072906d5f
|