Reputation: 35
data = DataFrame(np.arange(16).reshape((4, 4)),
index=['Ohio', 'Colorado', 'Utah', 'New York'],
columns=['one', 'two', 'three', 'four'])
outputs:
>>> data
one two three four
Ohio 0 1 2 3
Colorado 4 5 6 7
Utah 8 9 10 11
New York 12 13 14 15
I now want to:
I write this:
data.iloc[data['three']>5, [:2]]
and get this error:
>>> data.iloc[data['three']>5, [:2]]
File "<stdin>", line 1
data.iloc[data['three']>5, [:2]]
^
how do I fix this??
these are my imports
import pandas as pd
from pandas import Series, DataFrame
import numpy as np
Upvotes: 2
Views: 70
Reputation: 316
Your question is a bit unclear but what I have understood is you need Colorado and Utah in your final output. If that is the case, change the code to :
data[data['three']>5][:2]
Upvotes: 1