简体   繁体   English

Python yahoo_finance包,get_info()不起作用

[英]Python yahoo_finance package, get_info() not working

I use Python 3.5.2 from anaconda distribution, yahoo-finance 1.3.2 (latest) version. 我使用anaconda发行版的Python 3.5.2,yahoo-finance 1.3.2(最新版)。 The problem is the function get_info() only returns 'symbol', but in the description of this package, it should return other things, too, like 'start'. 问题是函数get_info()只返回'symbol',但是在这个包的描述中,它应该返回其他东西,比如'start'。 My main aim is to get 'start' value. 我的主要目标是获得“开始”的价值。

https://pypi.python.org/pypi/yahoo-finance/1.3.2 https://pypi.python.org/pypi/yahoo-finance/1.3.2

The codes are: 代码是:

from yahoo_finance import Share
yahoo = Share('YHOO')
yahoo.get_info()

My result is: 我的结果是:

{'symbol': 'YHOO'}

The results by the description of the package website is: 包裹网站描述的结果是:

{u'FullTimeEmployees': u'12200',
 u'Industry': u'Internet Information Providers',
 u'Sector': u'Technology',
 u'end': u'2014-05-03',
 u'start': u'1996-04-12',
 u'symbol': u'YHOO'}

Does anyone know why? 有谁知道为什么? And how can I get the value of 'start'? 我怎样才能获得'开始'的价值? Thanks! 谢谢!

It looks like returned data is in Jason/dictionary format. 看起来返回的数据是Jason /字典格式。 See examples in the link you provided, you need to import and use pprint (pretty print) to see all what is returned to you: 查看您提供的链接中的示例,您需要导入并使用pprint(漂亮打印)来查看返回给您的所有内容:

from pprint import pprint
pprint(yahoo.get_info()) 

If you don't have it yet, you will need to install it first: 如果您还没有,则需要先安装它:

pip install pprint

Then you need to use key:value (like in every dictionary) to narrow down to the part of the info you are looking for. 然后你需要使用key:value(比如在每个字典中)缩小到你要查找的信息的一部分。

The returned data is nested, which you will easy see with pprint. 返回的数据是嵌套的,您可以使用pprint轻松查看。 What you got is dictionary's first key:value, but data you want is inside, nested key:value 你得到的是字典的第一个键:值,但你想要的数据是嵌入式键:值

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

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