如何使用 Python Pandas 阅读和格式化 Weblink .csv
How to Read and Format a Weblink .csv with Python Pandas
我正在学习 Pandas,并尝试使用 Morningstar API 从 Morningstar 下载 .csv。
这里提供了一些关于如何使用 API 的非常好的说明(尽管它们不是 Python 特定的)... https://gist.github.com/hahnicity/45323026693cdde6a116
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 以正确的柱状形式阅读这篇文章?
非常感谢任何帮助。提前致谢!
好的,所以我不明白如何处理存储为 .csv 的 JSON 格式 Pandas... 所以我决定改用 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>')
此 returns 相关代码的日终定价。
您可以在此处找到文档并注册 API 密钥:
(https://docs.quandl.com/docs/in-depth-usage).
我正在学习 Pandas,并尝试使用 Morningstar API 从 Morningstar 下载 .csv。
这里提供了一些关于如何使用 API 的非常好的说明(尽管它们不是 Python 特定的)... https://gist.github.com/hahnicity/45323026693cdde6a116
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 以正确的柱状形式阅读这篇文章?
非常感谢任何帮助。提前致谢!
好的,所以我不明白如何处理存储为 .csv 的 JSON 格式 Pandas... 所以我决定改用 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>')
此 returns 相关代码的日终定价。
您可以在此处找到文档并注册 API 密钥: (https://docs.quandl.com/docs/in-depth-usage).