我在虚拟环境中工作.我能够在没有任何错误的情况下导入和使用pandas,但是当我尝试时import pandas_datareader
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import datetime as dt
from matplotlib import style
import pandas_datareader as web
Run Code Online (Sandbox Code Playgroud)
它给出了以下错误 -
Traceback (most recent call last):
File "stock.py", line 6, in <module>
import pandas_datareader as web
File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/__init__.py", line 2, in <module>
from .data import (DataReader, Options, get_components_yahoo,
File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/data.py", line 14, in <module>
from pandas_datareader.fred import FredReader
File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/fred.py", line 1, in <module>
from pandas.core.common import is_list_like
ImportError: cannot import name …Run Code Online (Sandbox Code Playgroud) import pandas_datareader
end = "2022-12-15"
start = "2022-12-15"
stock_list = ["TATAELXSI.NS"]
data = pandas_datareader.get_data_yahoo(symbols=stock_list, start=start, end=end)
print(data)
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,出现错误"TypeError: string indices must be integers"。
编辑:我已经更新了代码并将列表作为符号参数传递,但它仍然显示相同的错误
错误 :
Traceback (most recent call last):
File "C:\Users\Deepak Shetter\PycharmProjects\100DAYSOFPYTHON\mp3downloader.py", line 7, in <module>
data = pandas_datareader.get_data_yahoo(symbols=[TATAELXSI], start=start, end=end)
File "C:\Users\Deepak Shetter\PycharmProjects\100DAYSOFPYTHON\venv\lib\site-packages\pandas_datareader\data.py", line 80, in get_data_yahoo
return YahooDailyReader(*args, **kwargs).read()
File "C:\Users\Deepak Shetter\PycharmProjects\100DAYSOFPYTHON\venv\lib\site-packages\pandas_datareader\base.py", line 258, in read
df = self._dl_mult_symbols(self.symbols)
File "C:\Users\Deepak Shetter\PycharmProjects\100DAYSOFPYTHON\venv\lib\site-packages\pandas_datareader\base.py", line 268, in _dl_mult_symbols
stocks[sym] = self._read_one_data(self.url, self._get_params(sym))
File "C:\Users\Deepak Shetter\PycharmProjects\100DAYSOFPYTHON\venv\lib\site-packages\pandas_datareader\yahoo\daily.py", line …Run Code Online (Sandbox Code Playgroud) 这可能听起来像一个noob问题,但我坚持使用它,因为Python不是我最好的语言之一.
我有一个html页面,里面有一个表格,我想在其中显示一个pandas数据帧.最好的方法是什么?使用pandasdataframe.to_html?
PY
from flask import Flask;
import pandas as pd;
from pandas import DataFrame, read_csv;
file = r'C:\Users\myuser\Desktop\Test.csv'
df = pd.read_csv(file)
df.to_html(header="true", table_id="table")
Run Code Online (Sandbox Code Playgroud)
HTML
<div class="table_entrances" style="overflow-x: auto;">
<table id="table">
<thead></thead>
<tr></tr>
</table>
</div>
Run Code Online (Sandbox Code Playgroud) 我是Python 3x的新手,在mac上运行.
目前使用带有finance的python的sentdex教程,尝试运行以下脚本:
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
style.use('ggplot')
start = dt.datetime(2000,1,1)
end = dt.datetime(2016,12,31)
df = web.DataReader('TSLA', 'yahoo', start, end)
print(df.head())
Run Code Online (Sandbox Code Playgroud)
但是,这会返回以下错误消息:
Traceback (most recent call last):
File "F:\Downloads\Python Work\try figuring thigns out\finance\try.py", line 1, in <module>
import pandas_datareader.data as web
File "C:\Python36\lib\site-packages\pandas_datareader\__init__.py", line 3, in <module>
from .data import (get_components_yahoo, get_data_famafrench, get_data_google, get_data_yahoo, get_data_enigma, # noqa
File "C:\Python36\lib\site-packages\pandas_datareader\data.py", line 7, in <module>
from …Run Code Online (Sandbox Code Playgroud) 请注意:这个问题在下面成功回答了ptrj.我还在我的博客上写了一篇关于我对zipline的体验的博客文章,你可以在这里找到:https://financialzipline.wordpress.com
我的总部设在南非,我正在尝试将南非股票加载到一个数据框中,以便它可以提供带有股价信息的zipline.假设我正在寻找在JSE(约翰内斯堡证券交易所)上市的AdCorp控股有限公司:
Google财经为我提供了历史价格信息:
https://www.google.com/finance/historical?q=JSE%3AADR&ei=5G6OV4ibBIi8UcP-nfgB
雅虎财经没有关于该公司的信息.
https://finance.yahoo.com/quote/adcorp?ltr=1
在iPython Notebook中键入以下代码,可以获得Google财经信息的数据框:
start = datetime.datetime(2016,7,1)
end = datetime.datetime(2016,7,18)
f = web.DataReader('JSE:ADR', 'google',start,end)
Run Code Online (Sandbox Code Playgroud)
如果我显示f,我看到该信息实际上也与Google财经相关信息相对应:
这是Google财经完全关闭的价格,您可以在Google财经网站上看到2016-07-18的信息与我的数据框完全匹配.
但是,我不确定如何加载此数据框,以便zipline可以将其用作数据包.
如果查看给出的示例buyapple.py,您可以看到它只是从摄取的数据包中提取了apple share(APPL)的数据quantopian-quandl.这里的挑战是更换APPL,JSE:ADR以便它JSE:ADR每天订购10 份数据,而不是数据包,quantopian-quandl并将其绘制在图表上.
有谁知道如何做到这一点?网上几乎没有关于这个问题的例子......
这是buyapple.pyzipline示例文件夹中提供的代码:
from zipline.api import order, record, symbol
def initialize(context):
pass
def handle_data(context, data):
order(symbol('AAPL'), 10)
record(AAPL=data.current(symbol('AAPL'), 'price'))
# Note: this function can be removed if running
# this algorithm on quantopian.com
def analyze(context=None, …Run Code Online (Sandbox Code Playgroud) 我已经安装了pandas-daatreader但是已经弃用了用于下载历史股票价格数据的Google和Yahoo API.
import pandas_datareader.data as web
start_date = '2018-01-01'
end_date = '2018-06-08'
panel_data = web.DataReader('SPY', 'yahoo', start_date, end_date)
ImmediateDeprecationError:
Yahoo Daily has been immediately deprecated due to large breaks in the API without the
introduction of a stable replacement. Pull Requests to re-enable these data
connectors are welcome.
See https://github.com/pydata/pandas-datareader/issues
Run Code Online (Sandbox Code Playgroud)
你能告诉我如何使用Python访问历史股票价格吗?事实上,我有兴趣在研究时尽可能地提价.
谢谢.
由于雅虎停止了他们的 API 支持,pandas datareader 现在失败了
import pandas_datareader.data as web
import datetime
start = datetime.datetime(2016, 1, 1)
end = datetime.datetime(2017, 5, 17)
web.DataReader('GOOGL', 'yahoo', start, end)
HTTPError: HTTP Error 401: Unauthorized
Run Code Online (Sandbox Code Playgroud)
是否有任何非官方图书馆允许我们暂时解决这个问题?Quandl 上有什么吗?
我对使用熊猫数据阅读器的雅虎财务功能有疑问.我现在使用了几个月的股票代码清单,并按以下几行执行:
import pandas_datareader as pdr
import datetime
stocks = ["stock1","stock2",....]
start = datetime.datetime(2012,5,31)
end = datetime.datetime(2018,3,1)
f = pdr.DataReader(stocks, 'yahoo',start,end)
Run Code Online (Sandbox Code Playgroud)
从昨天开始我收到错误"IndexError:list index out of range",只有当我试图获得多个股票时才出现.
最近几天有什么变化我必须考虑或者你有更好的解决方案吗?
I am trying to download historical data from Yahoo using Pandas datareader. This is the code that I normally use:
import pandas_datareader as pdr
df = pdr.get_data_yahoo('SPY')
Run Code Online (Sandbox Code Playgroud)
However, I started receiving this error today: RemoteDataError: Unable to read URL: https://finance.yahoo.com/quote/SPY/history?period1=1467511200&period2=1625277599&interval=1d&frequency=1d&filter=history
Does anyone know how to solve it?
Thank you very much in advance!
尝试在 Python 311 上安装 lxml。遇到此错误。
\nPS C:\\Users\\chharlie\\Desktop\\code> pip install lxml\nCollecting lxml\n Using cached lxml-4.9.1.tar.gz (3.4 MB)\n Preparing metadata (setup.py) ... done\nBuilding wheels for collected packages: lxml\n Building wheel for lxml (setup.py) ... error\n error: subprocess-exited-with-error\n\n \xc3\x97 python setup.py bdist_wheel did not run successfully.\n \xe2\x94\x82 exit code: 1\n \xe2\x95\xb0\xe2\x94\x80> [74 lines of output]\n Building lxml version 4.9.1.\n Building without Cython.\n Building against pre-built libxml2 andl libxslt libraries\n running bdist_wheel\n running build\n running build_py\n creating build\n creating build\\lib.win-amd64-cpython-311\n creating build\\lib.win-amd64-cpython-311\\lxml\n copying …Run Code Online (Sandbox Code Playgroud)