【问题标题】:How to Read and Format a Weblink .csv with Python Pandas如何使用 Python Pandas 读取和格式化 Weblink .csv
【发布时间】:2017-09-16 00:08:06
【问题描述】:

我正在学习 Pandas,并尝试使用 Morningstar API 从 Morningstar 下载 .csv。

这里提供了一些关于如何使用 API 的非常好的说明(尽管它们不是 Python 特定的)...https://gist.github.com/hahnicity/45323026693cdde6a116

示例 weblink 是 hahnicity 在示例中使用的是: http://globalquote.morningstar.com/globalcomponent/RealtimeHistoricalStockData.ashx?ticker=F&showVol=true&dtype=his&f=d&curry=USD&range=1900-1-1|2014-10-10&isD=true&isS=true&hasF=true&ProdCode=DIRECT

我的代码是:

import pandas as pd    
path='http://globalquote.morningstar.com/globalcomponent/RealtimeHistoricalStockData.ashx?ticker=F&showVol=true&dtype=his&f=d&curry=USD&range=1900-1-1|2014-10-10&isD=true&isS=true&hasF=true&ProdCode=DIRECT'

df=pd.read_csv(path)

但是,返回的是乱码。我不确定如何让 Pandas 以正确的柱状形式阅读此内容?

非常感谢任何帮助。提前谢谢!

【问题讨论】:

  • 当我尝试该 URL 时,它只是挂起。你得到了什么?
  • 挂了20秒左右,然后下载。
  • 第二个链接会下载较少的历史数据,所以它应该是一个较小的文件。
  • 对我来说,它什么也不下载。它返回空。

标签: python pandas finance


【解决方案1】:

好的,所以我不明白如何使用 Pandas 处理存储为 .csv 的 JSON 格式......所以我决定改用 Quandl。它解决了我的问题。

import pandas as pd
df=pd.read_csv('https://www.quandl.com/api/v3/datasets/WIKI/<ticker_symbol>/data.csv?api_key=<api_key>')

这将返回相关代码的日终定价。

您可以在此处找到文档并注册 API 密钥: (https://docs.quandl.com/docs/in-depth-usage)。

【讨论】:

    猜你喜欢
    • 2021-08-07
    • 2015-11-09
    • 1970-01-01
    • 2021-06-06
    • 1970-01-01
    • 2015-08-30
    • 1970-01-01
    • 2022-11-01
    • 1970-01-01
    相关资源
    最近更新 更多