1

So, I am working with Blaze and wanted to perform this query on a dataframe:

SELECT col1,col2 FROM table WHERE col1 > 0

For SELECT *, this works: d[d.col1 > 0]. But I want col1 and col2 only rather than all columns. How should I go about it?

Thanks in advance!

Edit: Here I create d as: d = Data('postgresql://uri')

4

2 回答 2

1

我认为您可以使用第一个子集,然后使用布尔索引:

 print (d)
   col1  col2  col3
0    -1     4     7
1     2     5     8
2     3     6     9

d = d[['col1','col2']]
print (d)
   col1  col2
0    -1     4
1     2     5
2     3     6

print (d[d.col1 > 0])
   col1  col2
1     2     5
2     3     6

这与以下内容相同:

print (d[['col1','col2']][d.col1 > 0])
   col1  col2
1     2     5
2     3     6
于 2016-06-27T04:59:22.560 回答
1

这也有效:d[d.col1 > 0][['col1','col2']]

于 2016-06-27T05:17:21.870 回答