我很难完成任务,我需要你的帮助。 我有一个表(mytable),包括:
ID;price;cost; +70 more columns
我需要的是为每个ID找到什么是
cost*(price/(sum(price) "group by ID"))
每件商品的成本是相同的。
我在4页编码后到达了这个表,它在查询中是活着的,这意味着我不能再次调用它(至少我不想这样做)
我是如何以聪明的方式做到这一点的? 提前致谢
答案 0 :(得分:4)
如果我理解正确,你可以使用:
import numpy as np
import click
def eraseCloseAtoms(protein, atoms, cell, spacing=2, dmin=1.4, output=None):
print 'just need to erase close atoms'
if dmin > spacing:
print 'the spacing needs to be larger than dmin'
return
grid = [int(cell[0] / spacing), int(cell[1] / spacing), int(cell[2] / spacing)]
selected = list(atoms)
with click.progressbar(length=len(atoms), label='erasing close atoms') as bar:
for i, atom in enumerate(atoms):
bar.update(i)
erased = False
coord = np.array(atom[6])
for ix in [-1, 0, 1]:
if erased:
break
for iy in [-1, 0, 1]:
if erased:
break
for iz in [-1, 0, 1]:
if erased:
break
for j in protein:
protCoord = np.array(protein[int(j)][6])
trueDist = getMinDist(protCoord, coord, cell, vectors)
if trueDist <= dmin:
selected.remove(atom)
erased = True
break
if output is None:
return selected
else:
output.put(selected)
答案 1 :(得分:1)