qPython-kdb响应数据的类型转换 [英] qPython - Type conversion of kdb response data

查看:116
本文介绍了qPython-kdb响应数据的类型转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用qPython运行q查询时,我能够在pandas数据框中返回数据.我正在努力的是字符串"列的类型,即在q中以简单或混合(字符)列表形式显示的列.它们的dtype是object,其值以b'ab34knadke'的形式表示.但是,我想拥有的只是字符串的"ab34knadke"部分.

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.

我看过qPython的文档,但是我在努力获得熊猫和阅读器组件方面的努力.

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

任何想法都值得赞赏!

推荐答案

简而言之,您可以使用

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

qpython以机器可读的形式将kdb字节数组映射到python字节数组.因此,需要使用上述方法将它们制成人类可读的字符串.

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.

注意:仅当输入的字符串/字节数组使用UTF-8时,此解决方案才有效,但这是一个相当安全的选择.

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.

您可以在此处详细了解以下内容: https://www.geeksforgeeks.org/byte-objects-vs-string-python/

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

这篇关于qPython-kdb响应数据的类型转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆