python - 无法从数据库返回数组

标签 python sql dataframe snowflake-cloud-data-platform

我的 Snowflake 数据库中有一个表。我想从列中获取数据。

数据示例:

id          tid           categories
------------------------------------------------------------------------------
v-123       t-123         ["tx-b5mmqcpooa0p","tx-b5mmqcpood0p"]
b-123       t-124         ["tx-b5mmfcpooa0p","tx-b4mmqcpood0p"]
x-123       t-125         []
b-123       t-124         ["tx-b5mmfcpooa0p","tx-b4mmqcpood0p","tx-bmqcpood0p"]

我尝试使用pandas:

sql = SELECT id, tid, categories FROM table 
df = pandas.read.sql(con, sql)

我得到了这个结果:

id          tid           categories
---------------------------------------------------------------------------
"v-123"       "t-123"         " ["tx-b5mmqcpooa0p","tx-b5mmqcpood0p"] "
"b-123"       "t-124"         " ["tx-b5mmfcpooa0p","tx-b4mmqcpood0p"] "
"x-123"       "t-125"         " [] "
"b-123"       "t-124"         " ["tx-b5mmfcpooa0p","tx-b4mmqcpood0p","tx-bmqcpood0p"] "

“categories”的类型是字符串而不是数组(列表)。

我做错了什么?

谢谢!

最佳答案

关于python - 无法从数据库返回数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59503164/

相关文章:

python - BeautifulSoup : Extracting href from HTML ordered list

python - 如何在 Python 中声明重音变量

Mysql合并统计多列

python - 用于 SQL Alchemy 的 Py3k MySQL 驱动程序

mysql - 甚至显示学期时出现此错误

python - 将 Pandas 数据框转换为带有标题和数据类型的 numpy 数组

R data.table 子集子集

python - 反向(): 'NoneType' object is not callable

Python 循环 : Precise way to handle mapping matching lists

python - 如何调整行或列中的具体数据?