KxSystems / pyq

PyQ — Python for kdb+
http://code.kx.com/q/interfaces
Apache License 2.0
191 stars 49 forks source link

What's The Proper Way To Add A Column To q() Table, From Python List or NumpyArrary? #142

Closed GregGamba closed 3 years ago

GregGamba commented 3 years ago

Greetings, working solely in Python, I built a table from pandas dataframe. Have an unrelated list (can be NumpyArray) that I'm trying to add to the table.

I've tried to do: table.newcol, table[`newcol] assignment convert the list to a pandas.df and then the dataframe to a table and upsert the new table to original table

can't use table.update because I'm trying to use data from a python list, or can i?

How does one add columns to a pyq table using data from a python list? Thanks!

sashkab commented 3 years ago

Try using table.update statement:

>>> t = q('([]a: til 10; b:10*til 10)')
>>> t.show()
a b
----
0 0
1 10
2 20
3 30
4 40
5 50
6 60
7 70
8 80
9 90
>>> c = range(91, 101)
>>> t.update('c', c=c).show()
a b  c
--------
0 0  91
1 10 92
2 20 93
3 30 94
4 40 95
5 50 96
6 60 97
7 70 98
8 80 99
9 90 100
GregGamba commented 3 years ago

Thank you!