错误:一个系列的真值是模糊的。蟒蛇和放大器; pandas [英] Error: The truth value of a series is ambiguous. Python & Pandas
问题描述
我试图找出所有的MSFT和GOOG的期权合约有超过10,000批量的一天,并打印出symbol.I的名称正在错误系列的真值是不明确。使用a.empty,a.bool(),a.item(),a.any()或a.all()。该错误是第13行任何帮助是极大的AP preciated。
从pandas_datareader.data导入选项
进口大熊猫作为PD
从熊猫进口数据框
进口日期时间代号= ['歌','MSFT']
因为我在代号:
选项=选项(我,'雅虎')
数据= option.get_all_data() 如果data.Vol> 10000:
打印data.Symbol 其他:
通过
的问题是,条件( data.Vol> 10000
)返回布尔值的数组。 numpy的发出了错误,因为它不知道你是否是说要问是其中的任何值> X
,是所有这些值>?X
等。
在这种情况下,你应该使用逻辑索引,让你感兴趣的行:数据[data.Vol> 10000]
。
从那里,你可以得到所有相关符号:数据[data.Vol> 10000] .index.get_level_values('符号')
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
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')
这篇关于错误:一个系列的真值是模糊的。蟒蛇和放大器; pandas 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!