Bruno
Bruno

Reputation: 497

Python pandas-datareader fails on comma

I am trying to get a price of a stock from google by using pandas-datareader.data but when I try to call Amazon(amazons price right now is over 1,000) it gives me a value error. I assume it is because of the comma in the price. It automatically attempts to turn it into a float so I have no opportunity to use a .replace function.

ValueError: could not convert string to float: '1,001.30'

I seemingly cannot seem to find a workaround to this issue so any help would be very appreciated, thanks.

import pandas_datareader.data as web
def money(stock):
    #df = web.DataReader(stock, "google", start=start, end=end)
    df2 = web.get_quote_google(stock)

Upvotes: 1

Views: 105

Answers (1)

AaronDT
AaronDT

Reputation: 4060

I think there seems to be currently a compatibility issue with panads and pandas_datareader. However, this might solve your problem using yahoo-finance:

use pip install yahoo-finance to install the module and then run

import yahoo_finance
import pandas as pd

symbol = yahoo_finance.Share("AMZN")
google_df = symbol.get_price()

This gives me no error on the price of Amazon

Upvotes: 2

Related Questions