kdb

Save pandas dataframe in kdb/q

﹥>﹥吖頭↗ 提交于 2020-05-29 10:29:26
问题 What is the best way to save a pandas dataframe in kdb? Are there any libraries that can make it easier? The below code can apparently be used to loas something from kdb, but how do I save a dataframe into it? from qpython import qconnection with qconnection.QConnection(host = 'localhost', port = 5001, pandas = True) as q: ds = q('(1i;0Ni;3i)', pandas = True) print(ds) 回答1: To save a dataframe in KDB+ with qPython one can use the sync method of the QConnection class. Set the first parameter

How to sum multiple elements from single record

梦想与她 提交于 2020-01-25 02:17:45
问题 I have table trade:([]time:`time$(); sym:`symbol$(); price:`float$(); size:`long$()) with e.g. 1000 records, with e.g. 10 unique syms. I want to sum the first 4 prices for each sym. My code looks like: priceTable: select price by sym from trade; amountTable: select count price by sym from trade; amountTable: `sym`amount xcol amountTable; resultTable: amountTable ij priceTable; So my new table looks like: resultTable sym | amount price -------| -------------------------------------------------

select column from a table based on a variable name in q kdb

心不动则不痛 提交于 2020-01-17 01:37:46
问题 I have a table with columns sym and px t:([] sym:`GOOG`IBM`APPL; px:1000 2000 3000) Now, if I assign sym column to variable ab ab:`sym Then, running below query is giving rank error select ab from t / 'rank select `ab from t / 'rank I have a requirement where I need to save the column name to a variable based on a condition and then run select query on the column which is assigned to variable. Followed 'Q for Mortals' and 'Reference card' but no help. 回答1: There are a couple of ways you could

KDB+ / Q Syntax optimizations to oneliners

依然范特西╮ 提交于 2020-01-17 01:17:12
问题 I am definitly a q-mortal. I would even say a q-baby. Well I have some question how to put together my code from separate lines to a one-liner. I guess there is a way more elegant solution than mine. How to write the following statements in one line: q)t1:(3#3)?\:`8 q)t1[;0]:`abc In this table creation, how can I add another column which I have as list (like with the command ([]id:id_list;data:data_list;..... )). Till now I am creating another table and doing an inner join on them. I guess

[kdb+/q]: Convert adjacency matrix to adjacency list

喜欢而已 提交于 2020-01-16 08:23:26
问题 Given (rectangular) adjacency matrix m , how to construct adjacency list in q language? In QIdioms wiki I've found solution in the k language which when run through q console with k) command gives me 'vs error: m:(1 0 1;1 0 1) k) (^m)_vs &,/m 'vs Result should be: 0 0 1 1 0 2 0 2 This is what I was able to replicate in q : k) &,/m 0 2 3 5 q) where raze m 0 2 3 5 k 's ^ a.k.a. shape verb is missing in q so I just did: k) (^m) 000b 000b q) 2 3#0b 000b 000b Now, since: q) parse "vs" k) {x\:y} I

[kdb+/q]: Convert adjacency matrix to adjacency list

吃可爱长大的小学妹 提交于 2020-01-16 08:23:11
问题 Given (rectangular) adjacency matrix m , how to construct adjacency list in q language? In QIdioms wiki I've found solution in the k language which when run through q console with k) command gives me 'vs error: m:(1 0 1;1 0 1) k) (^m)_vs &,/m 'vs Result should be: 0 0 1 1 0 2 0 2 This is what I was able to replicate in q : k) &,/m 0 2 3 5 q) where raze m 0 2 3 5 k 's ^ a.k.a. shape verb is missing in q so I just did: k) (^m) 000b 000b q) 2 3#0b 000b 000b Now, since: q) parse "vs" k) {x\:y} I

pandas DataFrame drops index when passing to kdb+ (using qPython API)

别说谁变了你拦得住时间么 提交于 2020-01-15 12:34:07
问题 I am trying to pass time-series data from Python to q/kdb+ . One solution out there is qPython module, offering seamless conversion from q table/dictionary to Pandas. The problem is when trying to pass from Pandas to q , the time index in DataFrame (in the column Date ) doesn't quite make it to the q side. Reproducible code: import pandas.io.data as web import datetime import numpy import qpython.qconnection as qconnection # requires installation of qPython module from https://github.com