qPython - Type conversion of kdb response data

不问归期 提交于 2019-12-25 03:43:17

问题


When I run a q query using qPython, I am able to return the data in a pandas data frame. What I am struggling with are the types of the "string" columns, i.e. columns that are presented as simple or mixed (character) lists in q. Their dtype is object and the values are represented in the form b'ab34knadke'. What I would like to have, however, is just the "ab34knadke"-part as a string.

I have looked at the docs for qPython but I am struggling to fully get the pandas and reader components.

Any thoughts are much appreciated!


回答1:


In short you can fix the stringed columns using

data['stringcolumn']=data['stringcolumn'].str.decode('utf-8')

qpython maps the kdb byte arrays to python byte arrays in machine readable form. Consequently these need to be made into human readable strings using the above method.

Note: this solution solution is only valid if the strings/byte arrays coming in are in UTF-8 but this is a pretty safe bet.

You can read a little more about this here:https://www.geeksforgeeks.org/byte-objects-vs-string-python/



来源:https://stackoverflow.com/questions/53884308/qpython-type-conversion-of-kdb-response-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!