gpt4 book ai didi

python - 如何从查询结果中去除 "Decimal"

转载 作者:行者123 更新时间:2023-11-28 21:44:21 26 4
gpt4 key购买 nike

<分区>

我使用以下代码从 PostgreSQL 查询得到结果:

cur = con.cursor()
cur.execute("""SELECT to_char(tt.service_date,'yyyy-mm-01') AS txn_month,
SUM (tt.customer) AS customer,SUM (tt.tour) AS tour,
SUM (tt.distancetraveled) AS distancetraveled
FROM
tbl_travel as tt
GROUP BY
txn_month""")
rows = cur.fetchall()

我的查询结果是这样的:

[('2016-01-01', Decimal('11.0909090909090909'), Decimal('3.7272727272727273'), 58.5354545454545),
('2016-02-01', Decimal('11.6666666666666667'), Decimal('4.0000000000000000'), 74.8766666666667)]

我需要删除值前面的“Decimal”字符串并得到如下结果:

[('2016-01-01', '11.0909090909090909', '3.7272727272727273','58.5354545454545'),
('2016-02-01', '11.6666666666666667', '4.0000000000000000','74.8766666666667')]

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com