TypeError:在字典中搜索单词的可能匹配项时,类型为“float”的参数不适用

2024-05-14 09:47:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写一个预测股票价格的程序,我需要搜索一个我创建的字典,里面填有公司名称和公司股票代码名称,这是我需要返回的,以便使用Quandl检索股票价格

下面是我如何创建字典的:

cnames= pd.read_csv('secwiki_tickers.csv')
cnamesDict= pd.Series(cnames.Ticker.values, index=cnames.Name).to_dict()#Fills a dictionary with the 
csv file keys are company names values are ticker names

下面是我如何搜索字典并得到TypeError: argument of type 'float' is not iterable错误:

user_cname = input("Which company would you like to predict stock prices for?\n")
def searchForName(dictToSearch, lookup):
  for k,v in dictToSearch.items():
    if user_cname in k:    // here is where the error flags
      return v 





print(searchForName(cnamesDict, user_cname)) 

感谢您的帮助。CSV文件链接LINK


Tags: csvtheto名称字典公司arecompany

热门问题