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')

jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
delalli
  • 67
  • 2
  • 11

2 Answers2

1

I think you can use first subset and then boolean indexing:

 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

This is same as:

print (d[['col1','col2']][d.col1 > 0])
   col1  col2
1     2     5
2     3     6
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
1

This also works: d[d.col1 > 0][['col1','col2']]

harshit-sh
  • 358
  • 1
  • 3
  • 17