Jul-05-2020, 05:11 PM
(This post was last modified: Jul-05-2020, 05:11 PM by sportcardinal.)
How do I clear my cache path? I have a few API calls to get price data, but even though I am specifying to get data up until today, it seems like it only is getting data up to the time in which I first did it a week ago. My code is below. Is there any way to remove the cache path or clear it so I can get updated data? I am using Spyder within Anaconda.
import os import numpy as np import pandas as pd import pickle import quandl from datetime import datetime import matplotlib.pyplot as plt from scipy.optimize import minimize import plotly.offline as py import plotly.graph_objs as go import plotly.figure_factory as ff py.init_notebook_mode(connected=True) # Choose the number of portfolios to investigate num_ports = 100 altcoins = ['ETH'] #altcoins = ['ETH','XRP','LTC','XMR','DCR'] def get_quandl_data(quandl_id): '''Download and cache Quandl dataseries''' cache_path = '{}.pkl'.format(quandl_id).replace('/','-') try: f = open(cache_path, 'rb') df = pickle.load(f) print('Loaded {} from cache'.format(quandl_id)) except (OSError, IOError) as e: print('Downloading {} from Quandl'.format(quandl_id)) df = quandl.get(quandl_id, returns="pandas") df.to_pickle(cache_path) print('Cached {} at {}'.format(quandl_id, cache_path)) return df # Pull Kraken BTC price exchange data btc_usd_price_kraken = get_quandl_data('BCHARTS/KRAKENUSD') # Pull pricing data for 3 more BTC exchanges exchanges = ['BITSTAMP'] exchange_data = {} exchange_data['KRAKEN'] = btc_usd_price_kraken for exchange in exchanges: exchange_code = 'BCHARTS/{}USD'.format(exchange) btc_exchange_df = get_quandl_data(exchange_code) exchange_data[exchange] = btc_exchange_df def merge_dfs_on_column(dataframes, labels, col): '''Merge a single column of each dataframe into a new combined dataframe''' series_dict = {} for index in range(len(dataframes)): series_dict[labels[index]] = dataframes[index][col] return pd.DataFrame(series_dict) # Merge the BTC price dataseries' into a single dataframe btc_usd_datasets = merge_dfs_on_column(list(exchange_data.values()), list(exchange_data.keys()), 'Weighted Price') # Remove "0" values btc_usd_datasets.replace(0, np.nan, inplace=True)