Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clear Cache Path
#1
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Speeding up code using cache Peter 1 534 Jul-29-2023, 04:52 AM
Last Post: bowlofred
  Opinion: how should my scripts cache web download files? stevendaprano 0 726 Dec-17-2022, 12:19 AM
Last Post: stevendaprano
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,198 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  main libvlc error: stale plugins cache: schascheck 2 7,692 Dec-27-2020, 05:24 PM
Last Post: schascheck
  How to print cache from Decorators with Memoization OlgaM 2 2,048 Jan-29-2020, 05:06 PM
Last Post: OlgaM
  pip cache millpond 3 8,215 Jul-22-2019, 01:12 AM
Last Post: millpond
  python cache for small integer Uchikago 1 2,489 Jun-27-2019, 05:32 PM
Last Post: ichabod801
  Error in request, cache key a21250450 2 3,100 Apr-02-2019, 11:20 AM
Last Post: a21250450
  .pth file does not show up in sys.path when configuring path. arjunsingh2908 2 5,733 Jul-03-2018, 11:16 AM
Last Post: arjunsingh2908
  Clear cache blackclover 0 2,773 May-09-2018, 12:13 AM
Last Post: blackclover

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020