slowly changing dimension type 2 with pandas or parquet
Project description
pandas_scd
executing slowly changing dimension type 2 on pandas dataframes or parquet files
pandas_scd arguments:
-
src: pandas dataframe with the source of the SCD
-
tgt: pandas dataframe with the target of the SCD (target can be empty)
-
cols_to_track: list of columns to track changes (default is all
columns from the source table) -
tz: pytz time zone to use on start_ts and end_ts, default is None
(will use local time)
the return dataframe contain the entire target table with the new changes, ready for insert overwrite of the current target table
parquet_scd arguments:
- src: path to the source of the SCD
- tgt: path to the target of the SCD (target can be empty)
- cols_to_track: list of columns to track changes (default is all columns from the source table)
- tz: pytz time zone to use on start_ts and end_ts, default is None (will use local time)
there is no return value, the tgt path that was provided will be overwritten
Installation
pip install scd2
Getting started
for working with pandas:
from scd2 import SCD2
import pandas as df
tgt = pd.DataFrame.from_dict({'first_name': ["Chris"], 'last_name': ['Paul'], 'team': ["Clippers"], "start_ts": [datetime(2012, 1, 14, 3, 21, 34)], "end_ts": [None], "is_active": [True]})
src = pd.DataFrame.from_dict({'first_name': ["Chris"], 'last_name': ['Paul'], 'team': ['Suns']})
final_df = SCD2().pandas_scd2(src, tgt)
pandas_scd2 will return a dataframe with the entire new targer
tgt:
| first_name | last_name | team | start_ts | end_ts | is_active |
|------------|-----------|----------|---------------------|--------|-----------|
| Chris | Paul | Clippers | 2012-01-14 03:21:34 | | True |
src:
| first_name | last_name | team |
|------------|-----------|----------|
| Chris | Paul | Clippers |
final_df:
| first_name | last_name | team | start_ts | end_ts | is_active |
|------------|-----------|----------|---------------------|---------------------|-----------|
| Chris | Paul | Clippers | 2012-01-14 03:21:34 | 2018-01-01 00:00:00 | False |
| Chris | Paul | Suns | 2018-01-01 00:00:00 | | True |
for working with parquet:
src_parquet_path = '~/source.parquet'
tgt_parquet_path = '~/target.parquet'
SCD2().parquet_scd2(src, tgt)
parquet_scd2 will overide the current target (tgt_parquet_path)
src: pandas dataframe with the source of the SCD
tgt: pandas dataframe with the target of the SCD (target can be empty)
cols_to_track: list of columns to track changes (default is all columns from the source table)
tz: pytz time zone to use on start_ts and end_ts, default is None (will use local time)
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 scd2-1.0.0.tar.gz.
File metadata
- Download URL: scd2-1.0.0.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4cd133b1fb73852e3e3d58839fa8d2d531a9208ce2776e1232956fc3e1b8e58a
|
|
| MD5 |
0864b5bf6890255623be88575672e9a2
|
|
| BLAKE2b-256 |
64fd8d56e79dc8af624e133adf353385d59178929b26bd324cc1b474413ab36b
|
File details
Details for the file scd2-1.0.0-py3-none-any.whl.
File metadata
- Download URL: scd2-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5d3a58990fe8faa840ebaa786be48d50d3163ce9d3d4fffaef53fa5adc172a0
|
|
| MD5 |
1e458a320dac16f82f298a92474e429e
|
|
| BLAKE2b-256 |
9b2346cc159ea064a6f27bf28891c32951e261ac2c3e8b021d19a75ddbc3b9ce
|