Skip to main content

Python package for exploring and linking multiple SQL-like tables

Project description

Python package for exploring and linking multiple SQL-like tables

Description

This package will link multiple SQL-tables together to facilitate (potentially large-scale) analysis of data from various sources. All tables are implemented using Pandas Data.Frame objects.

Examples

In the following example, 3 tables are linked together via different columns and different data types. They form a tree: sex -> preference -> fruit. This package enables finding the favoriate fruits for ‘M’ ids by transversing this table tree automatically.

from tabletree import TableNode, TableTree, TableLink
import pandas as pd

tab1_list = list( zip([1,2,3,4], ['M', 'F', 'M', 'F'] ) )
tab2_list = list( zip(  [1,2,3,4], ['red', 'green', 'yellow', 'blue'] ) )
tab3_list = list( zip(  ['red', 'green', 'yellow', 'blue'], ['apple', 'grape', 'banana', 'berry'] ) )
tab4_list = list( zip(  [1,2,3,4], ['swimming', 'football', 'piano', 'painting'] ) )
tab1 = pd.DataFrame( tab1_list,   columns = ['tab1_v1', 'tab1_v2'])
tab2 = pd.DataFrame( tab2_list,   columns = ['tab2_v1', 'tab2_v2'])
tab3 = pd.DataFrame( tab3_list,   columns = ['tab3_v1', 'tab3_v2'])
tab4 = pd.DataFrame( tab4_list,   columns = ['tab4_v1', 'tab4_v2'])
tn1 = TableNode('sex', tab1)
tn2 = TableNode('preference', tab2)
tn3 = TableNode('fruit', tab3)
tn4 = TableNode('hobby', tab4)
ttree = TableTree(tn1)
ttree.addChildren(tn2, TableLink('tab1_v1', 'tab2_v1'))
ttree.addChildren(tn3, TableLink('tab2_v2', 'tab3_v1'))
ttree.addTN('sex', tn4, TableLink('tab1_v1', 'tab4_v1'))
print(ttree.getAncestors('hobby'))
#['sex', 'hobby']
ttree.findMatched('fruit', 'sex', tn1.df.tab1_v2 == 'M')
print( ttree.findMatched('hobby', 'sex', tn1.df.tab1_v2 == 'M') )
#tab4_v1   tab4_v2
#1         swimming
#3         piano
print(ttree)
#['sex', [['preference', [['fruit']]], ['hobby']]]

Note

Github: https://github.com/rluo/tabletree

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

tabletree-0.3.4.tar.gz (31.6 kB view details)

Uploaded Source

File details

Details for the file tabletree-0.3.4.tar.gz.

File metadata

  • Download URL: tabletree-0.3.4.tar.gz
  • Upload date:
  • Size: 31.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4

File hashes

Hashes for tabletree-0.3.4.tar.gz
Algorithm Hash digest
SHA256 8e0e9f7e2b1d4fd9854377f413496af0b5c897d2ce1d102fd8387738bddbca87
MD5 2ca0bf303e93baa58d0dbff80dec4417
BLAKE2b-256 68073918793da87c153d7bd77b71ca8070f6c34613d6d2db8c4496f89ddb14c8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page