I am trying to read a certain range of nonconsecutive columns from my file using python pandas read_table function. To that end, I am trying:
df=pd.read_table('genes.fpkm_trackingTest', usecols=[0:4, 8,9, 12:19])
The idea is that i am trying to use ":" to select the range of number of columns for usecols, rather than using column numbers separated with comma ",". I am getting a syntax error. If I use commas "," to separate column numbers, then it works fine.
df=pd.read_table('genes.fpkm_trackingTest', usecols=[0,1,2,4, 8,9, 12,13,14,15,16,17,18,19])
However, that can be cumbersome as sometimes i have to select 40 columns. How can i come around this?
I even tried
usecols=[range(0:4), 8, 9, range(12:19)]
but it also gave me errors.
I think that should be simple thing to solve but I couldnt find a solution online.
It should be...
Python 3:
usecols = [*range(0, 5), 8, 9, *range(12, 20)]
Python 2:
usecols = range(0, 5) + [8, 9] + range(12, 20)
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With