我想直接从 SQL 语句中提取结果表的列名:
query = """
select
sales.order_id as id,
p.product_name,
sum(p.price) as sales_volume
from sales
right join products as p
on sales.product_id=p.product_id
group by id, p.product_name;
"""
column_names = parse_sql(query)
# column_names:
# ['id', 'product_name', 'sales_volume']
Run Code Online (Sandbox Code Playgroud)
知道要做什么parse_sql()吗?生成的函数应该能够识别别名并删除表别名/标识符(例如“sales.”或“p.”)。
提前致谢!
我有两组坐标,想要找出该coo组的哪些坐标与该组中的任何坐标相同targets.我想知道coo集合中的索引,这意味着我想得到一个索引或bool的列表.
import numpy as np
coo = np.array([[1,2],[1,6],[5,3],[3,6]]) # coordinates
targets = np.array([[5,3],[1,6]]) # coordinates of targets
print(np.isin(coo,targets))
[[ True False]
[ True True]
[ True True]
[ True True]]
Run Code Online (Sandbox Code Playgroud)
期望的结果将是以下两个之一:
[False True True False] # bool list
[1,2] # list of concerning indices
Run Code Online (Sandbox Code Playgroud)
我的问题是,......
np.isin没有 - axis属性,所以我可以使用axis=1.True最后一个元素,这是错误的.我知道循环和条件,但我确信Python配备了更优雅的解决方案.