I am trying to get only workday data when importing Bitcoin quotes from yahoo finance. However, when I try to import it, it also gives weekend data, which I do not need. I transfered all data to .csv files to check what the problem was, and found that the bitcoin data included weekends and holidays. Since bitcoin is traded 24/7, I am getting more data. How do I get only data from workdays?
Code:
import pandas_datareader.data as web
import datetime as dt
start = dt.datetime(2017,1,1)
end = dt.datetime(2017,2,1)
a = web.DataReader('BTC-USD', 'yahoo', start, end)
a.to_csv('BTC.csv')
(Coded in Spyder, Python 3.7)
Use this:
import pandas_datareader.data as web
a = web.DataReader('BTC-USD', 'yahoo', '2017-01-01', '2017-02-01')
a_business_days = a[a.index.dayofweek < 5]
Related
hello guys, hope you're doing well.
i used a code that plots renko and counts the bars by importing the data of stocks from yahoo finance and it worked great, but i want to use forex data from yahoo finance in the code but it is not working.
Stocklist=['AAPL']
start='2016-1-1'
for stock in StockList:
data[stock]=pdr.get_data_yahoo(stock, start)
that's how i get stocks data and use it, but its not working for forex, for example EURUSD=X
start_date = dt.datetime.today()- dt.timedelta(4000)
end_date = dt.datetime.today()
stock ="USDJPY=X"
data = yf.download(stock, start_date, end_date)
it worked in this way guys
First off, thank you for taking the time to help me. We are using this python script that pulls data from Yahoo for a given time period.
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 (2007,1,1)
end = dt.datetime(2022,1,31)
df = web.DataReader('AAPL','yahoo', start, end)
df.to_csv('AAPl.csv')
The code above grabs the data we need from Yahoo for the AAPL stock for the dates we set, then it creates a CSV for that stock. The problem we are running into is that we have 5000 different stocks we need to do this for. We have a CSV file with all the different tickers we need to run this program over. How can we modify our code to run over the different stocks from our CSV? Instead of us having to run this program manually 5000 times.
You don't have to write the intermediate dataframes (for individual stock symbols) to file. Try something like:
tickers = pd.read_csv(r'path_to/symbols.csv')['symbol_column_name'].values
full_df = pd.DataFrame({})
for ticker in tickers:
df = web.DataReader(ticker,'yahoo', start, end)
full_df = pd.concat((full_df, df))
#Now write merged table to file
full_df.to_csv('my_output_table.csv')
I am trying to import stock data using Yahoo API as a source. I have tried it many times and I always get the same error, the start and end date are different from what I have passed. For example I pass the start and end date as '2015-1-1' & '2017-1-1' but the stock data I get start and ends at '2014-12-31' & '2016-12-30'. I dont know what I am doing wrong. I even tried using google but got a error as "data_sorce='google' not implemented."
Is there some other free data source I can use or correct the dates while using Yahoo? Jupyter notebook
You can import as yfinance and just enter a start and end when importing the data. Yahoo decommissioned their historical data API check out the Ran Aroussi the developer's of fix-yahoo-finance which is now yfinance blog where he details everything nicely https://aroussi.com/post/python-yahoo-finance
To install/upgrade yfinance using pip, run:
$ pip install yfinance
instead of this method
facebook = web.DateReader("FB", "yahoo", start, end)
can be in a format like this instead
override method from pandas_datareader by importing data as pdr
import yfinance as yf
yf.pdr_override() # <== the override :-)
# download dataframe using pandas_datareader
facebook = pdr.get_data_yahoo("FB", start="2015-1-1", end="2017-1-1")
or you can just use yfinance instead
import yfinance as yf
facebook = yf.download("FB", start="2015-1-1", end="2017-1-1")
I was trying to get stock information as follows:
from pandas.io.data import DataReader
import datetime
data = DataReader("F", "yahoo", datetime.datetime(1990, 1, 1),datetime.datetime(2002, 1, 1))
which fails with
IOError: after 3 tries, Yahoo! did not return a 200 for url 'http://ichart.finance.yahoo.com/table.csv?s=C001.F&a=0&b=1&c=2014&d=11&e=1&f=2017&g=d&ignore=.csv'
Up to now, I could not find a fix for this issue or a suitable work-around. Do you guys have any suggestions?
It seems 'yahoo'is no longer supported. Try "morningstar" or "google".
The simple yahoo financial link,that worked for years, is no longer supported.
I've heard of a work around that involves browser spoofing (wget from command line) requires browser aliasing to obtain time sensitive cookies that are then required for each request -- but I've never tried it myself since "morningstar" currently still works (but I miss yahoo's adjusted close).
#(Pascal 3.6)
import pandas as pd
import pandas_datareader.data as web
...
df = web.DataReader('MSFT','morningstar')
for idx, row in df.iterrows():
print(idx[1],row[0],row[1],row[2],row[3],row[4])
Can someone please elaborate on why yahoo suddenly stopped giving GOOG's historical prices? GOOG's historicla prices page isn't very helpful either.
Code I used to check: (AAPL works, GOOG doesn't)
import pandas.io.data as web
import datetime
print web.get_data_yahoo('AAPL', datetime.datetime(2010,1,1), datetime.datetime(2013,12,31))['Adj Close']
print web.get_data_yahoo('GOOG', datetime.datetime(2010,1,1), datetime.datetime(2013,12,31))['Adj Close']