I am making an API call to coinmarketcap.com and convert JSON object that is being returned to pandas data frame. I was wondering if there any way to store the data frame columns as constant and use it outside of the function?
def get_cmc_supply(): url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest' parameters = { 'start': '13', 'limit': '13', 'convert': 'USD', } header = { 'Accepts': 'application/json', 'X-CMC_PRO_API_KEY': '###################', } data = requests.get(url, headers = header,timeout=10).json() records = [] for item in data["data"]: records.append( { "name": item['symbol'], "supply": item['circulating_supply'], } ) df = pd.DataFrame.from_records(records) df = df.rename(columns={"name":"symbol"}) df = df.set_index('symbol') return df get_cmc_supply() How can I store df, so I can access it outside of the function without calling the get_cmc_supply() function again and getting a new supply data from API call?
to_csv()if that's what you're asking