question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use with Pandas Datareader?

See original GitHub issue

Would love some input on how to make that work, specifically when using DataReader and the Yahoo Finance API to get stock data. I can make requests for stock data using the DataReader once, and then after that I get an error, until the next day. My code looks simple:

import pandas as pd
import pandas_datareader.data as web
from datetime import datetime
from time import sleep
from http_request_randomizer.requests.proxy.requestProxy import RequestProxy

# list of stock's data to get
stocks = [

'USO',
'FXI',
'EEM'

]

start = datetime(2018, 9, 19)
end = datetime.now()

for i in stocks:
    sleep(5)
    
    try:
        data = web.DataReader(i, 'yahoo', start, end)
        df = data[['Date','Open','High','Low','Close','Adj Close','Volume']]
        # Round some of the results to 2 decimal places, then save .csv file
        df = df.round({"Open":2, "High":2, "Low":2, "Close":2, "Adj Close":2})
        df.to_csv(str(i) + '.csv')
        print('Successfully downloaded ' + str(i))
        continue
    
    except:
        print('Failed to download ' + str(i))
        continue

So how could one integrate the http randomizer into that? I tried playing around with it a bit but couldn’t figure it out. Something like replacing the url used in the request with the datareader somehow? If that makes sense?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
windowshoprcommented, Oct 21, 2019

Right on! I was able to get it working. Thanks a lot for the help!

0reactions
pgarefcommented, Oct 19, 2019

Hey @windowshopr – the path should be relative so it should be something like: https://github.com/pgaref/HTTP_Request_Randomizer/blob/78b305a3440f33cfd0caddb8ddf41b5eea974c68/http_request_randomizer/requests/proxy/requestProxy.py#L38

If you use the default (empty) UserAgentManager constructor, it will use the fake-useragent which is also fine (you will notice some log.warn messages)

Other than that let me know if you face any other issues and I can add the pandas-session functionality with some tests in the next release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pandas-datareader — pandas-datareader 0.10.0 documentation
Up-to-date remote data access for pandas. Works for multiple versions of pandas. Quick Start¶. Install using pip. pip install pandas- ...
Read more >
Using Python & Pandas Datareader to Analyze Financial Data
The pandas-datareader module is specifically designed to interface with some of the world's most popular financial data APIs, and import their data into...
Read more >
pandas-datareader Documentation - Read the Docs
Install using pip pip install pandas-datareader and then import and use one of the data readers. This example reads 5-years of 10-year ...
Read more >
Stock Market Analysis with Pandas - DataReader and Plotly ...
Analysing the stock prices demands a dataset that is continuously updating. In such scenarios, pandas have a special library called pandas- ...
Read more >
pydata/pandas-datareader: Extract data from a wide ... - GitHub
Extract data from a wide range of Internet sources into a pandas DataFrame. - GitHub - pydata/pandas-datareader: Extract data from a wide range...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found