WillKoehrsen / Data-Analysis

Data Science Using Python
https://medium.com/@williamkoehrsen/
MIT License
5.16k stars 3.64k forks source link

Load from local CSV #12

Open asfolcini opened 6 years ago

asfolcini commented 6 years ago

Hi there,

Pls consider to load data from local CSV.

`

# Initialization requires a ticker symbol
def __init__(self, ticker, exchange='WIKI', csv_repository=""):

    # Enforce capitalization
    ticker = ticker.upper()

    # Symbol is used for labeling plots
    self.symbol = ticker

    # Use Personal Api Key
    #quandl.ApiConfig.api_key = 'xxxxxxxxxxxxxxxxxxxxxxxx'

    if exchange in "CSV":
        print("Load from CSV file...")
        stock = pd.read_csv(self.symbol_to_path(ticker,csv_repository), index_col='Date',
                            parse_dates=True,
                            # usecols=['Date', 'Open','High','Low','Adj Close','Volume'],
                            na_values=['nan'])
        #print(stock.head(5))
    else:
        # Retrieval the financial data from QUANDL
        try:
            stock = quandl.get('%s/%s' % (exchange, ticker))

        except Exception as e:
            print('Error Retrieving Data.')
            print(e)
            return

... `

Check my modified version here: https://github.com/asfolcini/stocker/blob/master/stocker.py

uriencedric commented 6 years ago

Perhaps consider an adapter pattern here (ie QuandlSourceAdapter / CustomSourceApdapter ). It will provide extensible way of adding datasources for the library. What do you think ?

skyking363 commented 6 years ago

Sorry I can't use it from local csv to run. Can you give me an example? THX

kevb10 commented 5 years ago

open a PR with the changes requested

Rohan1280 commented 4 years ago

Sorry I can't use it from local csv to run. Can you give me an example? THX

df=pd.read_csv(r'C:\Users\Rohan\Desktop\ML\linear_ref_multivariate\homeprices.csv') @just add r before file location...After adding r, represents raw data.so u will not get any error after adding r.