-1

I have a pandas dataframe with a table I have parsed from a URL:

dfs = pd.read_html('https://pythonprogramming.net/parsememcparseface/', header = 0)
for df in dfs:
    print(df)

I have isolated a particular column called Internet Points:

df1 = df['Internet Points']

I'd like to filter search this column for Internet Points > 1000. I've tried:

if df1 > 10000:
print(df1)

However, I get an error: ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Mateus
  • 4,863
  • 4
  • 24
  • 32
NthA
  • 3
  • 2
  • 3
    Try `df1[df1>10000]` a simple boolean indexing – Bharath M Shetty Dec 02 '17 at 15:19
  • Possible duplicate of [Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()](https://stackoverflow.com/questions/36921951/truth-value-of-a-series-is-ambiguous-use-a-empty-a-bool-a-item-a-any-o) – wwii Dec 02 '17 at 15:30
  • [Boolean Indexing](http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing) – wwii Dec 02 '17 at 15:34

1 Answers1

0

You are probably looking for something like this

for _, val in df1.iteritems():
    if val > 1000:
        print(val)

Or you can also do it by using the method map

df1.map(lambda x: x if x > 1000 else None)

After you have filtered out the column using df1 = df['Internet Points'], the variable df1 becomes a pandas.core.series.Series type which is basically a Series. If you filter it using df1 > 10000, what you will get is just another Series with boolean values, so you can also do something like below:

print(df1[df1>10000])

If you want to output an array, you can also use

print(df1[df1>10000].values)
Hardian Lawi
  • 588
  • 5
  • 22