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.4.1.tar.gz
(21.4 kB
view hashes)
Built Distribution
Close
Hashes for DataProperty-0.4.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6818f8216e56196040d7250457dd025ea69228265942b306b5c0fd317582790a |
|
MD5 | 18555ac52cb2984e8bbc903821989ab5 |
|
BLAKE2b-256 | 5dd31a0e09d178e56d340c8dea6367888728fd15b4dcac434a4e6f0aba179f75 |