简体   繁体   English

错误:系列的真实值不明确。 蟒蛇和熊猫

[英]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()." 我试图找出当天交易量超过10,000的MSFT和GOOG的所有期权合约,并打印出交易品种的名称。我收到错误消息:“系列的真值不明确。请使用.empty,a.bool(),a.item(),a.any()或a.all()。” The error is on line 13. Any help is greatly appreciated. 该错误位于第13行。非常感谢您的帮助。

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

The problem is that the condition ( data.Vol > 10000 ) returns an array of boolean values. 问题在于条件( data.Vol > 10000 )返回布尔值数组。 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. NumPy发出该错误,是因为它不知道您是否要询问“这些值中的任何一个> x ?”,“所有这些值中的所有> x吗?”等。

In this case you should use logical indexing to get the rows you're interested in: data[data.Vol > 10000] . 在这种情况下,您应该使用逻辑索引来获取您感兴趣的行: data[data.Vol > 10000]

From there, you can get all the relevant symbols: data[data.Vol > 10000].index.get_level_values('Symbol') 从那里,您可以获得所有相关符号: data[data.Vol > 10000].index.get_level_values('Symbol')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM