RageAgainstheMachine
RageAgainstheMachine

Reputation: 949

Error: The truth value of a series is ambiguous. Python & Pandas

I'm trying to identify all the options contracts for MSFT and GOOG that have over 10,000 in volume for the day and to print out the name of the symbol.I am getting the error "The truth value of a series is ambiguous.Use a.empty, a.bool(), a.item(), a.any() or a.all()." The error is on line 13. Any help is greatly appreciated.

from pandas_datareader.data import Options
import pandas as pd
from pandas import DataFrame
import datetime

tickers = ['GOOG','MSFT']


for i in tickers:
    option = Options(i,'yahoo')
    data = option.get_all_data()

    if data.Vol > 10000:
         print data.Symbol

    else:
        pass

Upvotes: 1

Views: 1029

Answers (1)

wilywampa
wilywampa

Reputation: 1350

The problem is that the condition (data.Vol > 10000) returns an array of boolean values. NumPy emits that error because it can't know whether you mean to ask "are any of these values > x?", "are all of these values > x?", etc.

In this case you should use logical indexing to get the rows you're interested in: data[data.Vol > 10000].

From there, you can get all the relevant symbols: data[data.Vol > 10000].index.get_level_values('Symbol')

Upvotes: 1

Related Questions