PyKX Column Objects
pykx.wrappers.Column
pykx.wrappers.Column(column=None, name=None, value=None, is_tree=False)
Helper class creating queries for the Query API
abs
abs(iterator=None)
Return the absolute value of items in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the absolute value for all elements in a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], 2, -1]
... })
>>> tab.select(kx.Column('a').abs())
pykx.Table(pykx.q('
a
-
1
1
0
'))
acos
acos(iterator=None)
Calculate arccos for a column or items in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the arccos value for all elements in a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('a').acos())
pykx.Table(pykx.q('
a
--------
0
3.141593
1.570796
'))
Calculate the arccos value for each row of a specified column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('b').acos(iterator='each'))
pykx.Table(pykx.q('
b
------------
3.141593 0
1.570796 0
0
'))
asc
asc(iterator=None)
Sort the values within a column in ascending order
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Sort the values in a column ascending
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('a').asc())
pykx.Table(pykx.q('
a
--
-1
0
1
'))
Sort each row in a column ascending:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [3, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('b').asc(iterator='each'))
pykx.Table(pykx.q('
b
------
-1 1 2
1 2 3
1 2 3
'))
asin
asin(iterator=None)
Calculate arcsin for a column or items in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the arcsin value for all elements in a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('a').asin())
pykx.Table(pykx.q('
a
---------
1.570796
-1.570796
0
'))
Calculate the arcsin value for each row of a specified column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('b').asin(iterator='each'))
pykx.Table(pykx.q('
b
---------------------------
-1.570796 1.570796
0 1.570796
1.570796
'))
atan
atan(iterator=None)
Calculate arctan for a column or items in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the arctan value for all elements in a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('a').atan())
pykx.Table(pykx.q('
a
----------
0.7853982
-0.7853982
0
'))
Calculate the arctan value for each row of a specified column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('b').atan(iterator='each'))
pykx.Table(pykx.q('
b
------------------------------
-0.7853982 1.107149 0.7853982
0 0.7853982 1.107149
0.7853982 1.107149 1.249046
'))
avg
avg(iterator=None)
Calculate the average value for a column or items in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the value for all elements in a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0.5],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('a').avg())
pykx.Table(pykx.q('
a
---------
0.1666667
'))
Calculate average value for each row of a specified column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('b').avg(iterator='each'))
pykx.Table(pykx.q('
b
---------
0.6666667
1
2
'))
avgs
avgs(iterator=None)
Calculate a running average value for a column or items in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the running average across all elements in a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0.5],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('a').avgs())
pykx.Table(pykx.q('
a
---------
1
0
0.1666667
'))
Calculate average value for each row of a specified column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('b').avgs(iterator='each'))
pykx.Table(pykx.q('
b
----------------
-1 0.5 0.6666667
0 0.5 1
1 1.5 2
'))
ceiling
ceiling(iterator=None)
Calculate a nearest integer greater than or equal to items in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the ceiling of all elements in a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [0.1, 0.4, 3.6],
... 'b': [[-1.1, 2.2, 1.6], [0.3, 1.4, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('a').ceiling())
pykx.Table(pykx.q('
a
-
1
1
4
'))
Calculate the ceiling for all values in each row of a specified column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [0.1, 0.4, 3.6],
... 'b': [[-1.1, 2.2, 1.6], [0.3, 1.4, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('b').ceiling(iterator='each'))
pykx.Table(pykx.q('
b
------
-1 3 2
1 2 2
1 2 3
'))
cor
cor(other, iterator=None, col_arg_ind=0, project_args=None)
Calculate the correlation between a column and one of:
- Another column
- A vector of equal length to the column
- A PyKX variable in q memory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
The second column or variable (Python/q) to be used |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
0
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Calculate the correlation between two columns:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.exec(kx.Column('a').cor(kx.Column('b')))
pykx.FloatAtom(pykx.q('-0.9946109'))
Calculate the correlation between a column and variable in q memory:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> kx.q('custom_var:100?1f')
>>> tab.exec(kx.Column('a').cor(kx.Variable('custom_var')))
pykx.FloatAtom(pykx.q('-0.1670133'))
Calculate the correlation between a column and a Python variable:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> kx.q('custom_var:100?1f')
>>> tab.exec(kx.Column('a').cor(kx.random.random(100, 10.0)))
pykx.FloatAtom(pykx.q('-0.01448725'))
cos
cos(iterator=None)
Calculate cosine for a column or items in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the cosine value for all elements in a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('a').cos())
pykx.Table(pykx.q('
a
---------
0.5403023
0.5403023
1
'))
Calculate the cosine value for each row of a specified column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('b').cos(iterator='each'))
pykx.Table(pykx.q('
b
-------------------------------
0.5403023 -0.4161468 0.5403023
1 0.5403023 -0.4161468
0.5403023 -0.4161468 -0.9899925
'))
count
count(iterator=None)
Calculate the count of the number of elements in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the count of the number of elements in a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.exec(kx.Column('a').count())
pykx.LongAtom(pykx.q('3'))
Count the number of elements in each row of a specified column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 2], 1]
... })
>>> tab.exec(kx.Column('b').count(iterator='each')))
pykx.LongVector(pykx.q('3 2 1'))
cov
cov(other, sample=False, iterator=None, col_arg_ind=0, project_args=None)
Calculate the covariance/sample covariance between a column and one of:
- Another column
- A vector of equal length to the column
- A PyKX variable in q memory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
The second column or variable (Python/q) to be used |
required | |
sample |
Should calculations of covariance return the sample covariance (set True) covariance (set False {default}) |
False
|
|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
0
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Calculate the covariance between two columns:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.exec(kx.Column('a').cov(kx.Column('b')))
pykx.FloatAtom(pykx.q('-7.87451'))
Calculate the sample covariance between a column and variable in q memory:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> kx.q('custom_var:100?1f')
>>> tab.exec(kx.Column('a').cov(kx.Variable('custom_var'), sample=True))
pykx.FloatAtom(pykx.q('-0.1670133'))
Calculate the covariance between a column and a Python object:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.exec(kx.Column('a').cov(kx.random.random(100, 10.0)))
pykx.FloatAtom(pykx.q('-0.1093116'))
cross
cross(other, iterator=None, col_arg_ind=0, project_args=None)
Return the cross product (all possible combinations) between a column and:
- Another column
- A vector of items
- A PyKX variable in q memory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
The second column or variable (Python/q) to be used |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
0
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Generate the cross product of all values in two columns:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.select(kx.Column('a').cross(kx.Column('b')))
pykx.Table(pykx.q('
a
------------------
0.1392076 9.996082
0.1392076 9.797281
0.1392076 9.796094
..
'))
Calculate the cross product between a column and list in in q memory:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> kx.q('custom_var:til 3')
>>> tab.select(kx.Column('a').cross(kx.Variable('custom_var')))
pykx.Table(pykx.q('
a
-----------
0.1392076 0
0.1392076 1
0.1392076 2
0.2451336 0
..
'))
Calculate the cross product between a column and a Python object:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.select(kx.Column('a').cross([1, 2, 3]))
pykx.Table(pykx.q('
a
-----------
0.1392076 1
0.1392076 2
0.1392076 3
0.2451336 1
..
'))
deltas
deltas(iterator=None)
Calculate the difference between consecutive elements in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the difference between consecutive values in a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.exec(kx.Column('a').deltas())
pykx.LongVector(pykx.q('1 -2 1'))
Calculate the difference between consecutive values in each row of a specified column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('b').deltas(iterator='each'))
pykx.Table(pykx.q('
b
-------
-1 3 -1
0 1 1
1 1 1
'))
desc
desc(iterator=None)
Sort the values within a column in descending order
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Sort the values in a column descending
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('a').desc())
pykx.Table(pykx.q('
a
--
1
0
-1
'))
Sort each row in a column descending:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [3, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('b').desc(iterator='each'))
pykx.Table(pykx.q('
b
------
2 1 -2
3 2 1
3 2 1
'))
dev
dev(sample=False, iterator=None)
Calculate the standard deviation or sample standard deviation for items in a column or rows in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
Should calculations of standard deviation return the square root of the sample variance (set True) or the square root of the variance (set False {default}) |
False
|
|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the standard deviation of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 10.0),
... 'b': kx.random.random([100, 3], 10.0)
... })
>>> tab.exec(kx.Column('a').dev())
pykx.FloatAtom(pykx.q('2.749494'))
Calculate the sample standard deviation for each row in a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 10.0),
... 'b': kx.random.random([100, 3], 10.0)
... })
>>> tab.select(kx.Column('b').dev(sample=True, iterator='each'))
pykx.Table(pykx.q('
b
---------
3.068428
3.832719
2.032402
2.553458
2.527216
1.497015
..
'))
differ
differ(iterator=None)
Find locations where items in a column or rows in a column change value from one item to the next
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Determine if consecutive rows in a column are different values
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 2),
... 'b': kx.random.random([100, 3], 2)
... })
>>> tab.select(kx.Column('a').differ())
pykx.Table(pykx.q('
a
-
1
1
0
1
..
'))
Determine if consecutive values in vectors within a row have different values
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 2),
... 'b': kx.random.random([100, 3], 2)
... })
>>> tab.select(kx.Column('b').differ(iterator='each'))
pykx.Table(pykx.q('
b
----
110b
101b
110b
110b
..
'))
distinct
distinct(iterator=None)
Find unique items in a column or rows in a column change value from one item to the next
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Find all unique items in a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.exec(kx.Column('a').distinct())
pykx.LongVector(pykx.q('0 1 2 3 4'))
Find all unique items in each row of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('b').distinct(iterator='each'))
pykx.Table(pykx.q('
b
-----
0 2 3
1 3 4
4 2
1 4
1 0
,2
..
'))
div
div(other, iterator=None, col_arg_ind=0, project_args=None)
Return the greatest whole number divisor that does not exceed x%y between a column and:
- Another column
- An integer
- A vector of items equal in length to the column
- A PyKX variable in q memory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
The second column or variable (Python/q) to be used |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
0
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Calculate the greatest whole number divisor between two columns:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 5)),
... 'b': kx.q.desc(kx.random.random(100, 5))
... })
>>> tab.select(kx.Column('a').div(kx.Column('b')))
pykx.Table(pykx.q('
a
-
0
0
0
1
..
'))
Calculate the greatest whole number divisor between a column and an integer:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 5)),
... 'b': kx.q.desc(kx.random.random(100, 5))
... })
>>> tab.select(kx.Column('a').div(2))
pykx.Table(pykx.q('
a
-
1
0
2
0
..
'))
exp
exp(iterator=None)
Raise the expentional constant e
to a power determined by the elements of a column
or rows of the column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Raise the exponential constant e
to the power of values within a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.exec(kx.Column('a').exp())
pykx.FloatVector(pykx.q('1 2.718282 7.389056 20.08554..'))
Raise the exponential constant e
to the power of values within each row of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('b').exp(iterator='each'))
pykx.Table(pykx.q('
b
--------------------------
1 7.389056 20.08554
2.718282 20.08554 54.59815
54.59815 7.389056 7.389056
2.718282 54.59815 2.718282
..
'))
fby
fby(by, aggregate, data, by_table=False, data_table=False)
Helper function to create an fby
inside a Column object
Creates: (fby;(enlist;aggregate;data);by)
data_table
and by_table
can be set to True to create Table ParseTree of their input
fills
fills(iterator=None)
Replace null values with the preceding non-null value within a column or vector within rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Replace nulls in a column with preceding null values
>>> import pykx as kx
>>> value_list = kx.q.til(2)
>>> value_list.append(kx.LongAtom.null)
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, value_list),
... 'b': kx.random.random([100, 3], value_list)
... })
>>> tab.select(kx.Column('a').fills())
pykx.Table(pykx.q('
a
-
0
0
1
1
..
'))
Replace null values within each row of a column
>>> import pykx as kx
>>> value_list = kx.q.til(2)
>>> value_list.append(kx.LongAtom.null)
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, value_list),
... 'b': kx.random.random([100, 3], value_list)
... })
>>> tab.select(kx.Column('b').fills(iterator='each'))
pykx.Table(pykx.q('
b
-----
1 1 0
0 1 1
1 1 1
1 1 1
0 1 1
..
'))
first
first(iterator=None)
Retrieve the first item of a column or first item of each row in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Retrieve the first element of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.exec(kx.Column('a').first())
pykx.LongAtom(pykx.q('1'))
Retrieve the first element of each row of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [3, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('b').first(iterator='each'))
pykx.Table(pykx.q('
b
--
-1
0
1
'))
floor
floor(iterator=None)
Calculate a nearest integer less than or equal to items in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the floor of all elements in a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [0.1, 0.4, 3.6],
... 'b': [[-1.1, 2.2, 1.6], [0.3, 1.4, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('a').floor())
pykx.Table(pykx.q('
a
-
0
0
3
'))
Calculate the floor for all values in each row of a specified column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [0.1, 0.4, 3.6],
... 'b': [[-1.1, 2.2, 1.6], [0.3, 1.4, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('b').floor(iterator='each'))
pykx.Table(pykx.q('
b
------
-2 2 1
0 1 2
1 2 3
'))
null
null(iterator=None)
Determine if a value in a column or row of a column is a null value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Find null values within a column
>>> import pykx as kx
>>> value_list = kx.q.til(2)
>>> value_list.append(kx.LongAtom.null)
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, value_list),
... 'b': kx.random.random([100, 3], value_list)
... })
>>> tab.select(kx.Column('a').null())
pykx.Table(pykx.q('
a
-
1
0
0
0
1
..
'))
Calculate the floor for all values in each row of a specified column:
>>> import pykx as kx
>>> value_list = kx.q.til(2)
>>> value_list.append(kx.LongAtom.null)
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, value_list),
... 'b': kx.random.random([100, 3], value_list)
... })
>>> tab.select(kx.Column('b').null(iterator='each'))
pykx.Table(pykx.q('
b
----
000b
110b
011b
000b
..
'))
iasc
iasc(iterator=None)
Return the indexes needed to sort the values in a column/row in ascending order
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Find the indices needed to sort values in a column in ascending order
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, kx.q.til(10)),
... 'b': kx.random.random([100, 3], kx.q.til(10))
... })
>>> tab.select(kx.Column('a').iasc())
pykx.Table(pykx.q('
a
--
19
25
30
40
50
..
'))
Find the indices needed to sort each row in a column in ascending order
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, kx.q.til(10)),
... 'b': kx.random.random([100, 3], kx.q.til(10))
... })
>>> tab.select(kx.Column('b').iasc(iterator='each'))
pykx.Table(pykx.q('
b
----
2 0 1
1 0 2
0 1 2
0 1 2
..
'))
idesc
idesc(iterator=None)
Return the indexes needed to sort the values in a column/row in descending order
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Find the indices needed to sort values in a column in descending order
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, kx.q.til(10)),
... 'b': kx.random.random([100, 3], kx.q.til(10))
... })
>>> tab.select(kx.Column('a').idesc())
pykx.Table(pykx.q('
a
--
39
43
45
56
60
..
'))
Find the indices needed to sort each row in a column in descending order
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, kx.q.til(10)),
... 'b': kx.random.random([100, 3], kx.q.til(10))
... })
>>> tab.select(kx.Column('b').idesc(iterator='each'))
pykx.Table(pykx.q('
b
----
1 0 2
2 0 1
1 2 0
2 1 0
..
'))
inter
inter(other, iterator=None, col_arg_ind=0, project_args=None)
Return the intersection between a column and
- Another column
- A Python list/numpy array
- A PyKX variable in q memory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
The second column or variable (Python/q) to be used |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
0
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Return the distinct intersection of values between two columns:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 5)),
... 'b': kx.q.desc(kx.random.random(100, 10))
... })
>>> tab.exec(kx.Column('a').inter(kx.Column('b')).distinct())
pykx.LongVector(pykx.q('2 3 1 4 0'))
Return the distinct intersection of values between a column and variable in q memory:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 5)),
... 'b': kx.q.desc(kx.random.random(100, 10))
... })
>>> kx.q('custom_var:100?6')
>>> tab.exec(kx.Column('b').inter(kx.Variable('custom_var')).distinct())
pykx.LongVector(pykx.q('5 2 1 4 3 0'))
isin
isin(other, iterator=None, col_arg_ind=0, project_args=None)
Return a list of booleans indicating if the items in a column are in a specified
- Column
- Python list/numpy array
- A PyKX variable in q memory
Most commonly this function is used in where clauses to filter data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
The second column or variable (Python/q) to be used |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
0
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Query a table for anywhere where the column contains the element 'AAPL':
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, ['AAPL', 'GOOG', 'MSFT']),
... 'b': kx.random.random(100, 10)
... })
>>> tab.select(where=kx.Column('a').isin(['AAPL']))
pykx.Table(pykx.q('
a b
------
AAPL 7
AAPL 4
AAPL 2
..
'))
Return the distinct intersection of values between a column and variable in q memory:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, ['AAPL', 'GOOG', 'MSFT']),
... 'b': kx.random.random(100, 10)
... })
>>> kx.q('custom_var:1 2 3')
>>> tab.select(where=kx.Column('b').isin(kx.Variable('custom_var')))
pykx.Table(pykx.q('
a b
------
GOOG 2
MSFT 1
MSFT 2
GOOG 3
..
'))
last
last(iterator=None)
Retrieve the last item of a column or last item of each row in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Retrieve the last element of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.exec(kx.Column('a').last())
pykx.LongAtom(pykx.q('0'))
Retrieve the last element of each row of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [3, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('b').last(iterator='each'))
pykx.Table(pykx.q('
b
-
1
2
3
'))
like
like(other, iterator=None, col_arg_ind=0, project_args=None)
Return a list of booleans indicating whether an item in a column matches a supplied regex pattern. Most commonly this function is used in where clauses to filter data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
A string/byte array defining a regex pattern to be used for query |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
0
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Query a table for anywhere where the column contains the element 'AAPL':
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, ['TEST', 'tEsTing', 'string']),
... 'b': kx.random.random(100, 10)
... })
>>> tab.select(where=kx.Column('a').like('[tT]E*'))
pykx.Table(pykx.q('
a b
------
TEST 7
TEST 8
tEsTing 4
tEsTing 9
..
'))
log
log(iterator=None)
Calculate the natural logarithm of values in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the natural log of values within a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.exec(kx.Column('a').log())
pykx.FloatVector(pykx.q('0 1.386294 1.386294 1.098612..'))
Calculate the natural log of values within each row of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('b').log(iterator='each'))
pykx.Table(pykx.q('
b
----------------------------
1.386294 -0w 0
-0w -0w 1.098612
1.098612 0 0
1.386294 1.386294 1.098612
..
'))
lower
lower(iterator=None)
Change the case of string/symbol objects within a column to be all lower case
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Lower all values within a symbol list
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': ['TeStiNG', 'lOwER', 'FuncTion'],
... 'b': [1, 2, 3]
... })
>>> tab.select(kx.Column('a').lower())
pykx.Table(pykx.q('
a
--------
testing
lower
function
'))
ltrim
ltrim(iterator=None)
Remove whitespace at the start of character vectors(strings) within items in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Remove leading whitespace from all values in a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [b' test ', b' values ', b'trim '],
... 'b': [1, 2, 3]
... })
>>> tab.select(kx.Column('a').ltrim())
pykx.Table(pykx.q('
a
----------
"test "
"values "
"trim "
'))
mavg
mavg(other, iterator=None, col_arg_ind=1, project_args=None)
Calculate the simple moving average of items in a column for a specified window length. Any nulls after the first item are replaced by zero. The results are returned as a floating point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
An integer denoting the window to be used for calculation of the moving average |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 1. |
1
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Query a table for anywhere where the column contains the element 'AAPL':
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, ['TEST', 'tEsTing', 'string']),
... 'b': kx.random.random(100, 10)
... })
>>> tab.select(kx.Column('b').mavg(3))
pykx.Table(pykx.q('
b
--------
7
7.5
6.333333
5.333333
..
'))
max
max(iterator=None)
Find the maximum value in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Find the maximum values within a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.exec(kx.Column('a').max())
pykx.LongAtom(pykx.q('4'))
Find the maximum values within each row of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('b').max(iterator='each'))
pykx.Table(pykx.q('
b
-
2
3
4
4
..
'))
maxs
maxs(iterator=None)
Find the running maximum value in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Find the running maximum values within a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('a').maxs())
pykx.Table(pykx.q('
a
-
0
1
2
3
3
..
'))
Find the running maximum values within each row of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('b').maxs(iterator='each'))
pykx.Table(pykx.q('
b
-----
2 2 2
3 3 3
4 4 4
0 3 4
..
'))
mcount
mcount(other, iterator=None, col_arg_ind=1, project_args=None)
Calculate the moving count of non-null items in a column for a specified window length. The first 'other' items of the result are the counts so far, thereafter the result is the moving average
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
An integer denoting the window to be used for calculation of the moving count |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 1. |
1
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Calculate the moving count of non-null values within a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, [1, kx.LongAtom.null, 2]),
... 'b': kx.random.random(100, 10)
... })
>>> tab.select(kx.Column('a').mcount(3))
pykx.Table(pykx.q('
a
-
0
1
1
2
1
..
'))
md5
md5(iterator=None)
Apply MD5 hash algorithm on columns/rows within a column, it is suggested that this function should be used on rows rather than columns if being applied
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Apply the MD5 hash algorithm on each row of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [b' test ', b' values ', b'trim ']
... })
>>> tab.select(kx.Column('a').md5(iterator='each'))
pykx.Table(pykx.q('
a
----------------------------------
0x5609a772b21a22d88f3fb3d21f564eab
0xbb24d929a28559cc0aa65cb326d7662e
0xdeafa2fe0c90bcf8c722003bfdeb7c78
'))
mdev
mdev(other, iterator=None, col_arg_ind=1, project_args=None)
Calculate the moving standard deviation for items in a column over a specified window length. The first 'other' items of the result are the standard deviation of items so far, thereafter the result is the moving standard deviation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
An integer denoting the window to be used for calculation of the moving standard deviation |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 1. |
1
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Calculate the moving standard deviation of values within a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, [1, kx.LongAtom.null, 2]),
... 'b': kx.random.random(100, 10)
... })
>>> tab.exec(kx.Column('b').mdev(3))
pykx.FloatVector(pykx.q('0 1.5 1.699673 1.247219..'))
med
med(iterator=None)
Find the median value in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Find the median value of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.exec(kx.Column('a').med())
pykx.FloatAtom(pykx.q('2f'))
Find the median value for each row of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('b').med(iterator='each'))
pykx.Table(pykx.q('
b
-
3
2
3
3
..
'))
min
min(iterator=None)
Find the minimum value in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Find the minimum values within a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.exec(kx.Column('a').max())
pykx.LongAtom(pykx.q('0'))
Find the minimum values within each row of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('b').min(iterator='each'))
pykx.Table(pykx.q('
b
-
0
0
2
0
..
'))
mins
mins(iterator=None)
Find the running minimum value in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Find the running minimum values within a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('a').mins())
pykx.Table(pykx.q('
a
-
0
0
0
0
0
..
'))
Find the running minimum values within each row of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('b').mins(iterator='each'))
pykx.Table(pykx.q('
b
-----
0 0 0
0 0 0
2 2 2
2 2 0
..
'))
mmax
mmax(other, iterator=None, col_arg_ind=1, project_args=None)
Calculate the moving maximum for items in a column over a specified window length. The first 'other' items of the result are the maximum of items so far, thereafter the result is the moving maximum
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
An integer denoting the window to be used for calculation of the moving maximum |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 1. |
1
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Calculate the moving maximum of values within a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, [1, kx.LongAtom.null, 2]),
... 'b': kx.random.random(100, 10)
... })
>>> tab.exec(kx.Column('b').mmax(3))
pykx.LongVector(pykx.q('4 4 4 3 7..'))
mmin
mmin(other, iterator=None, col_arg_ind=1, project_args=None)
Calculate the moving minumum for items in a column over a specified window length. The first 'other' items of the result are the minimum of items so far, thereafter the result is the moving minimum
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
An integer denoting the window to be used for calculation of the moving minimum |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 1. |
1
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Calculate the moving minimum of values within a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, [1, kx.LongAtom.null, 2]),
... 'b': kx.random.random(100, 10)
... })
>>> tab.exec(kx.Column('b').mmin(3))
pykx.LongVector(pykx.q('4 1 0 0 0 2..'))
mod
mod(other, iterator=None, col_arg_ind=0, project_args=None)
Calculate the modulus of items in a column for a given value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
An integer denoting the divisor to be used when calculating the modulus |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 1. |
0
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Calculate the modulus for items within a column for a value 3:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, [1, kx.LongAtom.null, 2]),
... 'b': kx.random.random(100, 10)
... })
>>> tab.exec(kx.Column('b').mod(3))
pykx.LongVector(pykx.q('1 2 1 1 0..'))
msum
msum(other, iterator=None, col_arg_ind=1, project_args=None)
Calculate the moving sum of items in a column over a specified window length. The first 'other' items of the result are the sum of items so far, thereafter the result is the moving sum
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
An integer denoting the window to be used for calculation of the moving sum |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 1. |
1
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Calculate the moving sum of values within a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, [1, kx.LongAtom.null, 2]),
... 'b': kx.random.random(100, 10)
... })
>>> tab.exec(kx.Column('b').msum(3))
pykx.LongVector(pykx.q('4 5 5 4 10 12..'))
neg
neg(iterator=None)
Compute the negative value for all items in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Compute the negative value for all items in a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('a').neg())
pykx.Table(pykx.q('
a
--
0
-3
-4
-2
0
..
'))
prd
prd(iterator=None)
Calculate the product of all values in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Find the product of values within a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5.0),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.exec(kx.Column('a').prd())
pykx.FloatAtom(pykx.q('9.076436e+25'))
Find the product of values within each row of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('b').prd(iterator='each'))
pykx.Table(pykx.q('
b
-
0
0
32
0
0
48
..
'))
prds
prds(iterator=None)
Find the running product of values in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Find the running product of values within a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5.0),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('a').prds())
pykx.Table(pykx.q('
a
---------
0.8276359
3.833871
2.317464
3.940125
..
'))
Find the running product of values within each row of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('b').prds(iterator='each'))
pykx.Table(pykx.q('
b
-------
0 0 0
0 0 0
2 8 32
2 6 0
0 0 0
3 12 48
..
'))
prev
prev(iterator=None)
Retrieve the immediately preceding item in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Shift the values in column 'a' within a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5.0),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.update(kx.Column('a').prev())
pykx.Table(pykx.q('
a b
---------------
0 4 4
0.8276359 0 2 3
4.632315 2 4 4
0.6044712 2 3 0
'))
rank
rank(iterator=None)
Retrieve the positions items would take in a sorted list from a column
or items in a column, this is equivalent of calling iasc
twice`
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the rank of items in a list
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 1000),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.update(kx.Column('a').prev())
pykx.Table(pykx.q('
a b
--------
89 3 4 4
31 1 2 1
57 4 4 0
25 4 4 2
..
'))
ratios
ratios(iterator=None)
Calculate the ratio between consecutive elements in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the difference between consecutive values in a column
>>> import pykx as kx
>>> tab = kx.Table(data={
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 1000),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.exec(kx.Column('a').ratios())
pykx.FloatVector(pykx.q('908 0.3964758 1.45..'))
reciprocal
reciprocal(iterator=None)
Calculate the reciprocal of all elements in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the reciprocal of items in a column
>>> import pykx as kx
>>> tab = kx.Table(data={
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 1000),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.exec(kx.Column('a').reciprocal())
pykx.FloatVector(pykx.q('0.001101322 0.002777778 0.001915709..'))
reverse
reverse(iterator=None)
Reverse the elements of a column or contents of rows of the column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the reverse the items in a column
>>> import pykx as kx
>>> tab = kx.Table(data={
>>> tab = kx.Table(data={
... 'a': kx.q.til(100),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.exec(kx.Column('a').reverse())
pykx.LongVector(pykx.q('99 98 97..'))
rotate
rotate(other, iterator=None, col_arg_ind=1, project_args=None)
Shift the items in a column "left" or "right" by an integer amount denoted by the parameter other.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
An integer denoting the number of elements left(positve) or right(negative) which the column list will be shifted |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 1. |
1
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Shift the items in column b by 2 left:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, ['TEST', 'tEsTing', 'string']),
... 'b': kx.random.random(100, 10)
... })
>>> tab.select(kx.Column('b') & kx.Column('b').rotate(2).name('rot_b'))
pykx.Table(pykx.q('
b rot_b
-------
7 4
8 4
4 6
4 9
6 9
9 2
..
'))
Round a column of times to 15 minute buckets
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.q('100?0t')),
... 'b': kx.random.random(100, 10)
... })
>>> tab.select(kx.Column('b').avg(), by=kx.Column('a').minute.xbar(15))
pykx.KeyedTable(pykx.q('
a | b
-----| --------
00:00| 5.666667
00:15| 3
00:45| 1
01:00| 4.5
'))
rtrim
rtrim(iterator=None)
Remove whitespace from the end of character vectors(strings) within items in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Remove trailing whitespace from all values in a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [b' test ', b' values ', b'trim '],
... 'b': [1, 2, 3]
... })
>>> tab.select(kx.Column('a').ltrim())
pykx.Table(pykx.q('
a
---------
" test"
" values"
"trim"
'))
scov
scov(iterator=None)
Calculate the sample covariance for items in a column or rows in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the sample covariance of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 10.0),
... 'b': kx.random.random([100, 3], 10.0)
... })
>>> tab.exec(kx.Column('a').scov())
pykx.FloatAtom(pykx.q('8.983196'))
Calculate the sample covariance for each row in a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 10.0),
... 'b': kx.random.random([100, 3], 10.0)
... })
>>> tab.select(kx.Column('b').scov(iterator='each'))
pykx.Table(pykx.q('
b
---------
0.3333333
0.3333333
5.333333
1.333333
..
'))
sdev
sdev(iterator=None)
Calculate the sample deviation for items in a column or rows in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the sample deviation of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 10.0),
... 'b': kx.random.random([100, 3], 10.0)
... })
>>> tab.exec(kx.Column('a').sdev())
pykx.FloatAtom(pykx.q('8.983196'))
Calculate the sample deviation for each row in a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 10.0),
... 'b': kx.random.random([100, 3], 10.0)
... })
>>> tab.select(kx.Column('b').sdev(iterator='each'))
pykx.Table(pykx.q('
b
---------
0.3333333
0.3333333
5.333333
1.333333
..
'))
signum
signum(iterator=None)
Determine if the elements in a column or items in the row of a column is
- null or negative, returns -1i
- zero, returns 0i
- positive, returns 1i
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Determine if values are positive, null, zero or positive in a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.exec(kx.Column('a').signum())
pykx.IntVector(pykx.q('1 -1 0i'))
Find if values are positive, null, zero or positive in each row of a specified column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('b').signum(iterator='each'))
pykx.Table(pykx.q('
b
------
-1 1 1
0 1 1
1 1 1
'))
sin
sin(iterator=None)
Calculate sine for a column or items in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the sine value for all elements in a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('a').sin())
pykx.Table(pykx.q('
a
---------
0.841471
-0.841471
0
'))
Calculate the sine value for each row of a specified column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('b').sin(iterator='each'))
pykx.Table(pykx.q('
b
-----------------------------
-0.841471 0.9092974 0.841471
0 0.841471 0.9092974
0.841471 0.9092974 0.14112
'))
sqrt
sqrt(iterator=None)
Calculate the square root each element of a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Find the square root of each value within a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5.0),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.exec(kx.Column('a').sqrt())
pykx.FloatVector(pykx.q('1.152283 1.717071 1.253352..'))
Find the square root of each value within each row of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5.0),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('b').sqrt(iterator='each'))
pykx.Table(pykx.q('
b
--------------------------
1.732051 1.414214 1.732051
2 1.732051 2
1.732051 1.732051 1.414214
0 0 1.414214
1.732051 1.414214 1.414214
..
'))
string
string(iterator=None)
Convert all elements of a column to a PyKX string (CharVector)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Convert all elements of a column to strings
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1234, 1.01, 12142],
... 'b': [1, 2, 3]
... })
>>> tab.select(kx.Column('a').string())
pykx.Table(pykx.q('
a
-------
"1234"
"1.01"
"12142"
'))
sum
sum(iterator=None)
Calculate the sum of all values in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Find the sum of values within a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5.0),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.exec(kx.Column('a').sum())
pykx.FloatAtom(pykx.q('249.3847'))
Find the sum of values within each row of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5.0),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('b').sum(iterator='each'))
pykx.Table(pykx.q('
b
-
6
4
6
6
..
'))
sums
sums(iterator=None)
Find the running sum of values in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Find the running sum of values within a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5.0),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('a').sums())
pykx.Table(pykx.q('
a
---------
4.396227
8.42457
8.87813
11.26718
..
'))
Find the running sum of values within each row of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('b').sums(iterator='each'))
pykx.Table(pykx.q('
b
-------
0 3 6
3 4 4
1 3 6
3 3 6
..
'))
svar
svar(iterator=None)
Calculate the sample variance for items in a column or rows in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the sample variance of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 10.0),
... 'b': kx.random.random([100, 3], 10.0)
... })
>>> tab.exec(kx.Column('a').svar())
pykx.FloatAtom(pykx.q('8.394893'))
Calculate the sample variance for each row in a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 10.0),
... 'b': kx.random.random([100, 3], 10.0)
... })
>>> tab.select(kx.Column('b').svar(iterator='each'))
pykx.Table(pykx.q('
b
---------
6.023586
29.48778
6.318229
0.1609426
5.241295
..
'))
tan
tan(iterator=None)
Calculate tan for a column or items in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the tan value for all elements in a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('a').tan())
pykx.Table(pykx.q('
a
---------
1.557408
-1.557408
0
'))
Calculate the tan value for each row of a specified column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('b').tan(iterator='each'))
pykx.Table(pykx.q('
b
-----------------------------
-1.557408 -2.18504 1.557408
0 1.557408 -2.18504
1.557408 -2.18504 -0.1425465
'))
trim
trim(iterator=None)
Remove whitespace from the start and end of character vectors(strings) within items in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Remove trailing and following whitespace from all values in a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [b' test ', b' values ', b'trim '],
... 'b': [1, 2, 3]
... })
>>> tab.select(kx.Column('a').trim())
pykx.Table(pykx.q('
a
---------
"test"
"values"
"trim"
'))
union
union(other, iterator=None, col_arg_ind=0, project_args=None)
Return the union between a column and
- Another column
- A Python list/numpy array
- A PyKX variable in q memory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
The second column or variable (Python/q) to be used |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
0
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Return the distinct union of values between two columns:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 5)),
... 'b': kx.q.desc(kx.random.random(100, 10))
... })
>>> tab.exec(kx.Column('a').union(kx.Column('b')).distinct())
pykx.LongVector(pykx.q('0 1 2 3 4 9 8 7 6 5'))
Return the distinct union of values between a column and variable in q memory:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 5)),
... 'b': kx.q.desc(kx.random.random(100, 10))
... })
>>> kx.q('custom_var:100?6')
>>> tab.exec(kx.Column('b').union(kx.Variable('custom_var')).distinct())
pykx.LongVector(pykx.q('9 8 7 6 5 4 3 2 1 0'))
upper
upper(iterator=None)
Change the case of string/symbol objects within a column to be all upper case
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Convert all values within a symbol list to be upper case
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': ['TeStiNG', 'UpPer', 'FuncTion'],
... 'b': [1, 2, 3]
... })
>>> tab.select(kx.Column('a').upper())
pykx.Table(pykx.q('
a
--------
TESTING
UPPER
FUNCTION
'))
var
var(iterator=None, sample=False)
Calculate the variance or sample variance for items in a column or rows in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
Should calculation of variance return the sample variance (set True) or the variance (set False {default}) |
False
|
|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the variance of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 10.0),
... 'b': kx.random.random([100, 3], 10.0)
... })
>>> tab.exec(kx.Column('a').var())
pykx.FloatAtom(pykx.q('8.310944'))
Calculate the sample sample deviation for each row in a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 10.0),
... 'b': kx.random.random([100, 3], 10.0)
... })
>>> tab.select(kx.Column('b').var(sample=True, iterator='each'))
pykx.Table(pykx.q('
b
---------
6.023586
29.48778
6.318229
0.1609426
5.241295
..
'))
wavg
wavg(other, iterator=None, col_arg_ind=0, project_args=None)
Return the weighted average between a column and
- Another column
- A Python list/numpy array
- A PyKX variable in q memory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
The second column or variable (Python/q) to be used |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
0
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Return the weighted average between two columns:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 5)),
... 'b': kx.q.desc(kx.random.random(100, 10))
... })
>>> tab.exec(kx.Column('a').wavg(kx.Column('b')))
pykx.FloatAtom(pykx.q('2.456731'))
Return the weighted average between a column and variable in q memory:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 5)),
... 'b': kx.q.desc(kx.random.random(100, 10))
... })
>>> kx.q('custom_var:100?6')
>>> tab.exec(kx.Column('b').wavg(kx.Variable('custom_var')))
pykx.FloatAtom(pykx.q('2.431111'))
within
within(lower, upper, iterator=None, col_arg_ind=0, project_args=None)
Return a boolean list indicating whether the items of a column are within bounds of an lower and upper limite.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lower |
A sortable item defining the lower limit |
required | |
upper |
A sortable item defining the upper limit |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
0
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Return any rows where column a has a value within the range 1, 4:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.q.desc(kx.random.random(100, 10))
... })
>>> tab.select(where = kx.Column('a').within(1, 4))
pykx.Table(pykx.q('
a b
---
1 9
1 9
2 9
2 9
4 9
..
'))
Return any rows where column a has a value within a date range:
>>> import pykx as kx
>>> today = kx.DateAtom('today')
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, today - range(0, 10)),
... 'b': kx.q.desc(kx.random.random(100, 10))
... })
>>> tab.select(where=kx.Column('a').within(today - 5, today - 3))
pykx.FloatAtom(pykx.q('2.431111'))
wsum
wsum(other, iterator=None, col_arg_ind=0, project_args=None)
Return the weighted sum between a column and
- Another column
- A Python list/numpy array
- A PyKX variable in q memory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
The second column or variable (Python/q) to be used |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
0
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Return the weighted sum between two columns:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 5)),
... 'b': kx.q.desc(kx.random.random(100, 10))
... })
>>> tab.exec(kx.Column('a').wsum(kx.Column('b')))
pykx.FloatAtom(pykx.q('511f'))
Return the weighted sum between a column and variable in q memory:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 5)),
... 'b': kx.q.desc(kx.random.random(100, 10))
... })
>>> kx.q('custom_var:100?6')
>>> tab.exec(kx.Column('b').wsum(kx.Variable('custom_var')))
pykx.FloatAtom(pykx.q('1094f'))
xbar
xbar(other, iterator=None, col_arg_ind=1, project_args=None)
Round the elements of a column down to the nearest multiple of the supplied parameter other.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
An integer denoting the multiple to which all values will be rounded |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 1. |
1
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Round the items of a column to multiples of 3:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, ['TEST', 'tEsTing', 'string']),
... 'b': kx.random.random(100, 10)
... })
>>> tab.select(kx.Column('b').xbar(3))
pykx.Table(pykx.q('
b
-
3
6
9
6
..
'))
Round a column of times to 15 minute buckets
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.q('100?0t')),
... 'b': kx.random.random(100, 10)
... })
>>> tab.select(kx.Column('b').avg(), by=kx.Column('a').minute.xbar(15))
pykx.KeyedTable(pykx.q('
a | b
-----| --------
00:00| 5.666667
00:15| 3
00:45| 1
01:00| 4.5
'))
xexp
xexp(other, iterator=None, col_arg_ind=1, project_args=None)
Raise the elements of a column down to power of the value supplied as the parameter other.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
An integer denoting the power to which all values will be raised |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 1. |
1
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Round the items of a column to multiples of 3:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 10.0),
... 'b': kx.random.random(100, 10)
... })
>>> tab.select(kx.Column('b').xexp(2))
pykx.Table(pykx.q('
b
---
64
512
4
8
2
..
'))
xlog
xlog(other, iterator=None, col_arg_ind=1, project_args=None)
Return the base-N logarithm for the elements of a column where N is specified by the parameter other.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
An integer denoting the logarithmic base to which all values will be set |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 1. |
1
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Round the items of a column to multiples of 3:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 10.0),
... 'b': kx.random.random(100, 10)
... })
>>> tab.select(kx.Column('b').xlog(2))
pykx.Table(pykx.q('
b
--------
1.584963
3.169925
2.321928
3.169925
..
'))
xprev
xprev(other, iterator=None, col_arg_ind=1, project_args=None)
For a specified column return for each item in the column the item N elements before it. Where N is specified by the parameter other.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
An integer denoting the number of indices before elements in the list to retrieve the value of |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 1. |
1
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Shift the data in a column by 3 indexes:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 10.0),
... 'b': kx.random.random(100, 10)
... })
>>> tab.select(kx.Column('a') & kx.Column('a').xprev(3).name('lag_3_a'))
pykx.Table(pykx.q('
a lag_3_a
-------------------
3.927524
5.170911
5.159796
4.066642 3.927524
1.780839 5.170911
3.017723 5.159796
'))
hour
hour()
Retrieve the hour information from a temporal column
Examples:
Retrieve hour information from a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, kx.TimestampAtom.inf),
... 'b': kx.random.random([100, 3], 10.0)
... })
>>> tab.exec(kx.Column('a').hour)
pykx.IntVector(pykx.q('11 1 13 12..'))
minute
minute()
Retrieve the minute information from a temporal column
Examples:
Retrieve minute information from a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, kx.TimestampAtom.inf),
... 'b': kx.random.random([100, 3], 10.0)
... })
>>> tab.exec(kx.Column('a').minute)
pykx.MinuteVector(pykx.q('11:55 01:09 13:43..'))
date
date()
Retrieve the date information from a temporal column
Examples:
Retrieve date information from a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, kx.TimestampAtom.inf),
... 'b': kx.random.random([100, 3], 10.0)
... })
>>> tab.exec(kx.Column('a').date)
pykx.DateVector(pykx.q('2122.07.05 2120.10.23..'))
year
year()
Retrieve the year information from a temporal column
Examples:
Retrieve year information from a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, kx.TimestampAtom.inf),
... 'b': kx.random.random([100, 3], 10.0)
... })
>>> tab.exec(kx.Column('a').year)
pykx.IntVector(pykx.q('2122 2120 2185..'))
day
day()
Retrieve the day of the month information from a temporal column
Examples:
Retrieve day of month information from a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, kx.TimestampAtom.inf),
... 'b': kx.random.random([100, 3], 10.0)
... })
>>> tab.exec(kx.Column('a').day)
pykx.IntVector(pykx.q('7 10 12..'))
month
month()
Retrieve the month information from a temporal column
Examples:
Retrieve month information from a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, kx.TimestampAtom.inf),
... 'b': kx.random.random([100, 3], 10.0)
... })
>>> tab.exec(kx.Column('a').month)
pykx.IntVector(pykx.q('7 10 12..'))
second
second()
Retrieve the second information from a temporal column
Examples:
Retrieve year information from a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, kx.TimestampAtom.inf),
... 'b': kx.random.random([100, 3], 10.0)
... })
>>> tab.exec(kx.Column('a').second)
pykx.SecondVector(pykx.q('11:55:50 01:09:35..'))
add
add(other, iterator=None, col_arg_ind=0, project_args=None)
Add the content of a column to one of
- Another column
- A vector of equal length to the column
- A PyKX variable in q memory
Note in it's most basic usage this is equivalent to
>>> kx.Column('x') + kx.Column('y')
It is supplied as a named function to allow the use of iterators when adding elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
The second column or variable (Python/q) to be used |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
0
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Add together two columns:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.select(kx.Column('a').add(kx.Column('b')))
pykx.Table(pykx.q('
a
--------
9.967087
9.870729
9.882342
9.95924
..
'))
Add a value of 3 to each element of a column.
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.select(kx.Column('a').add(3))
pykx.Table(pykx.q('
a
--------
3.021845
3.044166
3.062797
3.051352
..
'))
For each row in a column add 3 and 4 to the value of the column This makes use of each-left and each-right from q:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.select(kx.Column('a').add([3, 4], iterator='/:\:'))
pykx.Table(pykx.q('
a
-----------------
3.021845 4.021845
3.044166 4.044166
3.062797 4.062797
3.166843 4.166843
..
'))
name
name(name)
Rename the resulting column from a calculation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
The name to be given to the column following application of function |
required |
Examples:
Rename the column 'a' to 'average_a' following application of the function average
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0.5],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('a').average().name('average_a'))
pykx.Table(pykx.q('
average_a
---------
0.1666667
'))
average
average(iterator=None)
Calculate the average value for a column or items in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the value for all elements in a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0.5],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('a').average())
pykx.Table(pykx.q('
a
---------
0.1666667
'))
Calculate average value for each row of a specified column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('b').average(iterator='each'))
pykx.Table(pykx.q('
b
---------
0.6666667
1
2
'))
cast
cast(other, iterator=None, col_arg_ind=1, project_args=None)
Convert the content of a column to another PyKX type
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
The name of the type to which your column should be cast or the lower case letter used to define it in q, for more information see https://code.kx.com/q/ref/cast/ |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
1
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Cast a column containing PyKX long objects to float objects
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, kx.q.til(10)),
... 'b': kx.random.random(100, kx.q.til(10))
... })
>>> tab.dtypes
pykx.Table(pykx.q('
columns datatypes type
-----------------------------------
a "kx.LongAtom" "kx.LongAtom"
b "kx.LongAtom" "kx.LongAtom"
'))
>>> tab.select(
... kx.Column('a') &
... kx.Column('a').cast('float').name('a_float') &
... kx.Column('b')).dtypes
pykx.Table(pykx.q('
columns datatypes type
-------------------------------------
a "kx.LongAtom" "kx.LongAtom"
a_float "kx.FloatAtom" "kx.FloatAtom"
b "kx.LongAtom" "kx.LongAtom"
'))
correlation
correlation(other, iterator=None, col_arg_ind=0, project_args=None)
Calculate the correlation between a column and one of
- Another column
- A vector of equal length to the column
- A PyKX variable in q memory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
The second column or variable (Python/q) to be used |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
0
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Calculate the correlation between two columns:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.exec(kx.Column('a').cor(kx.Column('b')))
pykx.FloatAtom(pykx.q('-0.9946109'))
Calculate the correlation between a column and variable in q memory:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> kx.q('custom_var:100?1f')
>>> tab.exec(kx.Column('a').correlation(kx.Variable('custom_var')))
pykx.FloatAtom(pykx.q('-0.1670133'))
Calculate the correlation between a column and a Python variable:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> kx.q('custom_var:100?1f')
>>> tab.exec(kx.Column('a').correlation(kx.random.random(100, 10.0)))
pykx.FloatAtom(pykx.q('-0.01448725'))
covariance
covariance(
other, sample=False, iterator=None, col_arg_ind=0, project_args=None
)
Calculate the covariance/sample covariance between a column and one of:
- Another column
- A vector of equal length to the column
- A PyKX variable in q memory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
The second column or variable (Python/q) to be used |
required | |
sample |
Should calculations of covariance return the sample covariance (set True) covariance (set False {default}) |
False
|
|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
0
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Calculate the covariance between two columns:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.exec(kx.Column('a').covariance(kx.Column('b')))
pykx.FloatAtom(pykx.q('-7.87451'))
Calculate the sample covariance between a column and variable in q memory:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> kx.q('custom_var:100?1f')
>>> tab.exec(kx.Column('a').covariance(kx.Variable('custom_var'), sample=True))
pykx.FloatAtom(pykx.q('-0.1670133'))
Calculate the covariance between a column and a Python object:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.exec(kx.Column('a').covariance(kx.random.random(100, 10.0)))
pykx.FloatAtom(pykx.q('-0.1093116'))
divide
divide(other, iterator=None, col_arg_ind=0, project_args=None)
Divide the content of one column by
- Another column
- Python/Numpy list/item
- A PyKX variable in q memory
Note in it's most basic usage this is equivalent to
>>> kx.Column('x') % kx.Column('y')
It is supplied as a named function to allow the use of iterators when adding elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
The second column or variable (Python/q) to be used |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
0
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Divide on column by another column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.select(kx.Column('a').divide(kx.Column('b')))
pykx.Table(pykx.q('
a
-----------
0.0021965
0.004494546
0.006395103
0.01703797
..
'))
Divide each element of a column by 3.
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.select(kx.Column('a').divide(3))
pykx.Table(pykx.q('
a
-----------
0.007281574
0.01472198
0.02093233
0.05561419
..
'))
For each row in a column divide the row by both 3 and 4 independently. This makes use of each-left and each-right from q:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.select(kx.Column('a').divide([3, 4], iterator='/:\:'))
pykx.Table(pykx.q('
a
---------------------
0.06553417 0.08737889
0.1324978 0.1766638
0.188391 0.251188
0.5005277 0.6673703
..
'))
drop
drop(other, iterator=None, col_arg_ind=1, project_args=None)
Drop N rows from a column or N elements from items in a column using an iterator. Where N is specified by the other parameter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
An integer defining the number of elements to drop |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
1
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Drop 3 rows from a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, kx.q.til(10)),
... 'b': kx.random.random([100, 3], kx.q.til(10))
... })
>>> tab.select(kx.Column('a').drop(3).count())
pykx.Table(pykx.q('
a
--
10
12
24
27
..
'))
fill
fill(other, iterator=None, col_arg_ind=1, project_args=None)
Replace all null values in a column with a specified 'other' parameter
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
The value which should replace nulls within a column |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
1
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Replace all nulls in column a with a value 0, displaying that only 0, 1 and 2 exist in this column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, [1, kx.LongAtom.null, 2]),
... 'b': kx.random.random(100, 10)
... })
>>> tab.exec(kx.Column('a').fill(0).distinct())
pykx.LongVector(pykx.q('1 0 2'))
index_sort
index_sort(ascend=True, iterator=None)
Return the indexes needed to sort the values in a column/row in ascending order or descending order
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ascend |
A boolean indicating if the index return should be retrieved in ascending or descending order |
True
|
|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Find the indices needed to sort values in a column in ascending order
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, kx.q.til(10)),
... 'b': kx.random.random([100, 3], kx.q.til(10))
... })
>>> tab.select(kx.Column('a').index_sort())
pykx.Table(pykx.q('
a
--
10
12
24
27
..
'))
Find the indices needed to sort values in a column in descending order
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, kx.q.til(10)),
... 'b': kx.random.random([100, 3], kx.q.til(10))
... })
>>> tab.select(kx.Column('a').index_sort(ascend=False))
pykx.Table(pykx.q('
a
--
1
15
44
50
..
'))
join
join(other, iterator=None, col_arg_ind=0, project_args=None)
Join the content of one column with another or using an iterator produce complex combinations of items in a column with:
- Another Column
- A list/item which is to be joined to the column
- A variable in q memory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
The Column, list, item or variable to be joined to the original column |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
0
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Join the content of one column to another column (extend the column)
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> len(tab.select(kx.Column('a').join(kx.Column('b'))))
200
Join the value 3 to each row in a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.select(kx.Column('a').join(3, iterator="'"))
pykx.Table(pykx.q('
a
---
1 3
2 3
1 3
3 3
..
'))
len
len(iterator=None)
Calculate the length of the number of elements in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the length of the number of elements in a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.exec(kx.Column('a').len())
pykx.LongAtom(pykx.q('3'))
Count the length of elements in each row of a specified column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 2], 1]
... })
>>> tab.exec(kx.Column('b').len(iterator='each')))
pykx.LongVector(pykx.q('3 3 3'))
modulus
modulus(other, iterator=None, col_arg_ind=1, project_args=None)
Calculate the modulus of items in a column for a given value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
An integer denoting the divisor to be used when calculating the modulus |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 1. |
1
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Calculate the modulus for items within a column for a value 3:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, [1, kx.LongAtom.null, 2]),
... 'b': kx.random.random(100, 10)
... })
>>> tab.exec(kx.Column('b').mod(3))
pykx.LongVector(pykx.q('1 2 1 1 0..'))
multiply
multiply(other, iterator=None, col_arg_ind=0, project_args=None)
Multiply the content of a column to one of
- Another column
- Python/Numpy list
- A PyKX variable in q memory
Note in it's most basic usage this is equivalent to
>>> kx.Column('x') * kx.Column('y')
It is supplied as a named function to allow the use of iterators when adding elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
The second column or variable (Python/q) to be used |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
0
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Multiply together two columns:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.select(kx.Column('a').multiply(kx.Column('b')))
pykx.Table(pykx.q('
a
---------
0.2172511
0.4339994
0.616638
1.633789
..
'))
Multiply each element of a column by 3.
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.select(kx.Column('a').multiply(3))
pykx.Table(pykx.q('
a
----------
0.06553417
0.1324978
0.188391
0.5005277
..
'))
For each row in a column multiply the row by both 3 and 4 independently. This makes use of each-left and each-right from q:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.select(kx.Column('a').multiply([3, 4], iterator='/:\:'))
pykx.Table(pykx.q('
a
---------------------
0.06553417 0.08737889
0.1324978 0.1766638
0.188391 0.251188
0.5005277 0.6673703
..
'))
next_item
next_item(iterator=None)
Retrieve the immediately following item in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Shift the values in column 'a' within a column forward one
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5.0),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.update(kx.Column('a').next_item())
pykx.Table(pykx.q('
a b
---------------
0 4 4
0.8276359 0 2 3
4.632315 2 4 4
0.6044712 2 3 0
'))
previous_item
previous_item(iterator=None)
Retrieve the immediately preceding item in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Shift the values in column 'a' within a column back one
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5.0),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.update(kx.Column('a').previous_item())
pykx.Table(pykx.q('
a b
---------------
0 4 4
0.8276359 0 2 3
4.632315 2 4 4
0.6044712 2 3 0
'))
product
product(iterator=None)
Calculate the product of all values in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Find the product of values within a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5.0),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.exec(kx.Column('a').product())
pykx.FloatAtom(pykx.q('9.076436e+25'))
Find the product of values within each row of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('b').product(iterator='each'))
pykx.Table(pykx.q('
b
-
0
0
32
0
0
48
..
'))
products
products(iterator=None)
Find the running product of values in a column or rows of a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Find the running product of values within a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5.0),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('a').products())
pykx.Table(pykx.q('
a
---------
0.8276359
3.833871
2.317464
3.940125
..
'))
Find the running product of values within each row of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 5),
... 'b': kx.random.random([100, 3], 5)
... })
>>> tab.select(kx.Column('b').products(iterator='each'))
pykx.Table(pykx.q('
b
-------
0 0 0
0 0 0
2 8 32
2 6 0
0 0 0
3 12 48
..
'))
sort
sort(ascend=True, iterator=None)
Sort the values within a column in ascending or descending order
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ascend |
Should the data be sorted in ascending or descending order |
True
|
|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Sort the values in a column ascending
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('a').sort())
pykx.Table(pykx.q('
a
--
-1
0
1
'))
Sort the values in descending order:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': [1, -1, 0],
... 'b': [[-1, 2, 1], [0, 1, 2], [1, 2, 3]]
... })
>>> tab.select(kx.Column('a').sort(ascend=False))
pykx.Table(pykx.q('
a
--
1
0
-1
'))
subtract
subtract(other, iterator=None, col_arg_ind=0, project_args=None)
Subtract from a column one of
- The values of another column
- Python/Numpy list/value
- A PyKX variable in q memory
Note in it's most basic usage this is equivalent to
>>> kx.Column('x') - kx.Column('y')
It is supplied as a named function to allow the use of iterators when adding elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
The second column or variable (Python/q) to be used |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
0
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Subtract the values of two columns:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.select(kx.Column('a').subtract(kx.Column('b')))
pykx.Table(pykx.q('
a
---------
-9.923397
-9.782397
-9.756748
-9.625555
..
'))
Substract 3 from each element of a column.
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.select(kx.Column('a').subtract(3))
pykx.Table(pykx.q('
a
---------
-2.978155
-2.955834
-2.937203
-2.833157
..
'))
For each row in a column subtract 3 and 4 from the row independently. This makes use of each-left and each-right from q:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.q.asc(kx.random.random(100, 10.0)),
... 'b': kx.q.desc(kx.random.random(100, 10.0))
... })
>>> tab.select(kx.Column('a').subtract([3, 4], iterator='/:\:'))
pykx.Table(pykx.q('
a
-------------------
-2.978155 -3.978155
-2.955834 -3.955834
-2.937203 -3.937203
-2.833157 -3.833157
..
'))
take
take(other, iterator=None, col_arg_ind=1, project_args=None)
Retrieve the first N rows from a column or N elements from items from a column using an iterator. Where N is specified by the other parameter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
An integer defining the number of elements to retrieve |
required | |
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
|
col_arg_ind |
Determines the index within the multivariate function where the column parameter will be used. Default 0. |
1
|
|
project_args |
The argument indices of a multivariate function which will be projected on the function before evocation with use of an iterator. |
None
|
Examples:
Retrieve 3 rows from a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, kx.q.til(10)),
... 'b': kx.random.random([100, 3], kx.q.til(10))
... })
>>> tab.select(kx.Column('a').take(3).count())
pykx.Table(pykx.q('
a
--
10
12
24
'))
value
value(iterator=None)
When passed an EnumVector will return the corresponding SymbolVector
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the variance of a column
>>> import pykx as kx
>>> tab = kx.q('([] a:`sym?`a`b`c`a)')
>>> tab.exec(kx.Column('a'))
pykx.EnumVector(pykx.q('`sym$`a`b`c`a'))
>>> tab.exec(kx.Column('a').value())
pykx.SymbolVector(pykx.q('`a`b`c`a'))
variance
variance(sample=False, iterator=None)
Calculate the variance or sample variance for items in a column or rows in a column
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
Should calculation of variance return the sample variance (set True) or the variance (set False {default}) |
False
|
|
iterator |
What iterator to use when operating on the column
for example, to execute per row, use |
None
|
Examples:
Calculate the variance of a column
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 10.0),
... 'b': kx.random.random([100, 3], 10.0)
... })
>>> tab.exec(kx.Column('a').variance())
pykx.FloatAtom(pykx.q('8.310944'))
Calculate the sample sample deviation for each row in a column:
>>> import pykx as kx
>>> tab = kx.Table(data={
... 'a': kx.random.random(100, 10.0),
... 'b': kx.random.random([100, 3], 10.0)
... })
>>> tab.select(kx.Column('b').variance(sample=True, iterator='each'))
pykx.Table(pykx.q('
b
---------
6.023586
29.48778
6.318229
0.1609426
5.241295
..
'))
pykx.wrappers.QueryPhrase
pykx.wrappers.QueryPhrase(phrase, names=None, are_trees=False)
Special wrapper for a list which will be treated as a QueryPhrase. For use with the Query API