Python library for extract property from data.
Project description
DataProperty
Summary
Python library for extract property from data.
Installation
pip install DataProperty
Usage
Extract property of data
e.g. Extract property of a float value
from dataproperty import DataProperty
DataProperty(-1.0)
data=-1.0, typename=FLOAT, align=right, str_len=4, integer_digits=1, decimal_places=1, additional_format_len=1
e.g. Extract property of a int value
from dataproperty import DataProperty
DataProperty(123456789)
data=123456789, typename=INT, align=right, str_len=9, integer_digits=9, decimal_places=0, additional_format_len=0
e.g. Extract property of a str value
from dataproperty import DataProperty
DataProperty("abcdefgh")
data=abcdefgh, typename=STRING, align=left, str_len=8, integer_digits=nan, decimal_places=nan, additional_format_len=0
e.g. Extract property of a time value (from datetime)
import datetime
from dataproperty import DataProperty
DataProperty(datetime.datetime(2017, 1, 1, 0, 0, 0))
data=2017-01-01 00:00:00, typename=DATETIME, align=left, str_len=19, integer_digits=nan, decimal_places=nan, additional_format_len=0
e.g. Extract property of a time value (from str)
DataProperty("2017-01-01T01:23:45+0900")
data=2017-01-01 01:23:45+09:00, typename=DATETIME, align=left, str_len=25, integer_digits=nan, decimal_places=nan, additional_format_len=0
e.g. Extract property of a bool value.
DataProperty(True)
data=True, typename=BOOL, align=left, str_len=4, integer_digits=nan, decimal_places=nan, additional_format_len=0
Extract property of data for each data from a matrix
import datetime
from dataproperty import PropertyExtractor, Typecode
import six
def display(prop_matrix, name):
six.print_()
six.print_("---------- %s ----------" % (name))
for prop_list in prop_matrix:
six.print_([getattr(prop, name) for prop in prop_list])
dt = datetime.datetime(2017, 1, 1, 0, 0, 0)
inf = float("inf")
nan = float("nan")
data_matrix = [
[1, 1.1, "aa", 1, 1, True, inf, nan, dt],
[2, 2.2, "bbb", 2.2, 2.2, False, "inf", "nan", dt],
[3, 3.33, "cccc", -3, "ccc", "true", inf, "NAN", "2017-01-01T01:23:45+0900"],
]
prop_extractor = PropertyExtractor()
prop_extractor.data_matrix = data_matrix
prop_matrix = prop_extractor.extract_data_property_matrix()
six.print_("---------- typename ----------")
for prop_list in prop_matrix:
six.print_([Typecode.get_typename(prop.typecode) for prop in prop_list])
display(prop_matrix, "data")
display(prop_matrix, "align")
display(prop_matrix, "str_len")
display(prop_matrix, "integer_digits")
display(prop_matrix, "decimal_places")
---------- typename ---------- ['INT', 'FLOAT', 'STRING', 'INT', 'INT', 'BOOL', 'INFINITY', 'NAN', 'DATETIME'] ['INT', 'FLOAT', 'STRING', 'FLOAT', 'FLOAT', 'BOOL', 'INFINITY', 'NAN', 'DATETIME'] ['INT', 'FLOAT', 'STRING', 'INT', 'STRING', 'BOOL', 'INFINITY', 'NAN', 'DATETIME'] ---------- data ---------- [1, 1.1, 'aa', 1, 1, True, inf, nan, datetime.datetime(2017, 1, 1, 0, 0)] [2, 2.2, 'bbb', 2.2, 2.2, False, inf, nan, datetime.datetime(2017, 1, 1, 0, 0)] [3, 3.33, 'cccc', -3, 'ccc', True, inf, nan, datetime.datetime(2017, 1, 1, 1, 23, 45, tzinfo=tzoffset(None, 32400))] ---------- align ---------- [right, right, left, right, right, left, left, left, left] [right, right, left, right, right, left, left, left, left] [right, right, left, right, left, left, left, left, left] ---------- str_len ---------- [1, 3, 2, 1, 1, 4, 3, 3, 19] [1, 3, 3, 3, 3, 5, 3, 3, 19] [1, 4, 4, 2, 3, 4, 3, 3, 25] ---------- integer_digits ---------- [1, 1, nan, 1, 1, nan, nan, nan, nan] [1, 1, nan, 1, 1, nan, nan, nan, nan] [1, 1, nan, 1, nan, nan, nan, nan, nan] ---------- decimal_places ---------- [0, 1, nan, 0, 0, nan, nan, nan, nan] [0, 1, nan, 1, 1, nan, nan, nan, nan] [0, 2, nan, 0, nan, nan, nan, nan, nan]
Extract property of data for each column from a matrix
import datetime
from dataproperty import PropertyExtractor, Typecode
import six
def display(prop_list, name):
six.print_()
six.print_("---------- %s ----------" % (name))
six.print_([getattr(prop, name) for prop in prop_list])
dt = datetime.datetime(2017, 1, 1, 0, 0, 0)
inf = float("inf")
nan = float("nan")
data_matrix = [
[1, 1.1, "aa", 1, 1, True, inf, nan, dt],
[2, 2.2, "bbb", 2.2, 2.2, False, "inf", "nan", dt],
[3, 3.33, "cccc", -3, "ccc", "true", inf, "NAN", "2017-01-01T01:23:45+0900"],
]
prop_extractor = PropertyExtractor()
prop_extractor.header_list = [
"int", "float", "str", "num", "mix", "bool", "inf", "nan", "time"]
prop_extractor.data_matrix = data_matrix
col_prop_list = prop_extractor.extract_column_property_list()
six.print_("---------- typename ----------")
six.print_([Typecode.get_typename(prop.typecode) for prop in col_prop_list])
display(col_prop_list, "align")
display(col_prop_list, "padding_len")
display(col_prop_list, "decimal_places")
---------- typename ---------- ['INT', 'FLOAT', 'STRING', 'FLOAT', 'STRING', 'BOOL', 'INFINITY', 'NAN', 'DATETIME'] ---------- align ---------- [right, right, left, right, left, left, left, left, left] ---------- padding_len ---------- [3, 5, 4, 3, 3, 5, 3, 3, 25] ---------- decimal_places ---------- [nan, 2, nan, 1, 1, nan, nan, nan, nan]
Dependencies
Python 2.6+ or 3.3+
Test dependencies
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
DataProperty-0.5.0.tar.gz
(21.7 kB
view details)
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 DataProperty-0.5.0.tar.gz.
File metadata
- Download URL: DataProperty-0.5.0.tar.gz
- Upload date:
- Size: 21.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc47be582c89949448c9a37c5730723b018b893fc451c7cb4955e7708f6d8efa
|
|
| MD5 |
865feca79468704203a68904376a4eb6
|
|
| BLAKE2b-256 |
eb09122adc6e9d7b84b42fb0ef8eeeb7520eb00ade162484a0a2aaa086a5a223
|
File details
Details for the file DataProperty-0.5.0-py2.py3-none-any.whl.
File metadata
- Download URL: DataProperty-0.5.0-py2.py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5910082fb2285d7e353c86be685bf0507502c7e7371bc29bd091829d915c266f
|
|
| MD5 |
3d8159b37760eb56a069802f8a8d8fab
|
|
| BLAKE2b-256 |
8b8ae39ed29168cce9995539bd475608d640353b832044c553f4af3b4de520af
|