Trying to access the value
associated with the date_added
key
in a dictionary returned from coinmarketcap which I have named data_dict
The value which I am trying to retrieve is 2013-04-28T00:00:00.000Z
data_dict = {'status': {'timestamp': '2021-10-07T11:14:06.481Z', 'error_code': 0, 'error_message': None, 'elapsed': 10, 'credit_count': 1, 'notice': None}, 'data': {'1': {'id': 1, 'name': 'Bitcoin', 'symbol': 'BTC', 'category': 'coin', 'description': 'Bitcoin (BTC) is a cryptocurrency . Users are able to generate BTC through the process of mining. Bitcoin has a current supply of 18,837,087. The last known price of Bitcoin is 54,121.57993093 USD and is up 5.16 over the last 24 hours. It is currently trading on 8524 active market(s) with $46,641,776,977.64 traded over the last 24 hours. More information can be found at https://bitcoin.org/.', 'slug': 'bitcoin', 'logo': 'https://s2.coinmarketcap.com/static/img/coins/64x64/1.png', 'subreddit': 'bitcoin', 'notice': '', 'tags': ['mineable', 'pow', 'sha-256', 'store-of-value', 'state-channels', 'coinbase-ventures-portfolio', 'three-arrows-capital-portfolio', 'polychain-capital-portfolio', 'binance-labs-portfolio', 'arrington-xrp-capital', 'blockchain-capital-portfolio', 'boostvc-portfolio', 'cms-holdings-portfolio', 'dcg-portfolio', 'dragonfly-capital-portfolio', 'electric-capital-portfolio', 'fabric-ventures-portfolio', 'framework-ventures', 'galaxy-digital-portfolio', 'huobi-capital', 'alameda-research-portfolio', 'a16z-portfolio', '1confirmation-portfolio', 'winklevoss-capital', 'usv-portfolio', 'placeholder-ventures-portfolio', 'pantera-capital-portfolio', 'multicoin-capital-portfolio', 'paradigm-xzy-screener'], 'tag-names': ['Mineable', 'PoW', 'SHA-256', 'Store of Value', 'State channels', 'Coinbase Ventures Portfolio', 'Three Arrows Capital Portfolio', 'Polychain Capital Portfolio', 'Binance Labs Portfolio', 'Arrington XRP capital', 'Blockchain Capital Portfolio', 'BoostVC Portfolio', 'CMS Holdings Portfolio', 'DCG Portfolio', 'DragonFly Capital Portfolio', 'Electric Capital Portfolio', 'Fabric Ventures Portfolio', 'Framework Ventures', 'Galaxy Digital Portfolio', 'Huobi Capital', 'Alameda Research Portfolio', 'A16Z Portfolio', '1Confirmation Portfolio', 'Winklevoss Capital', 'USV Portfolio', 'Placeholder Ventures Portfolio', 'Pantera Capital Portfolio', 'Multicoin Capital Portfolio', 'Paradigm XZY Screener'], 'tag-groups': ['OTHER', 'CONSENSUS_ALGORITHM', 'CONSENSUS_ALGORITHM', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY', 'PROPERTY'], 'urls': {'website': ['https://bitcoin.org/'], 'twitter': [], 'message_board': ['https://bitcointalk.org'], 'chat': [], 'explorer': ['https://blockchain.coinmarketcap.com/chain/bitcoin', 'https://blockchain.info/', 'https://live.blockcypher.com/btc/', 'https://blockchair.com/bitcoin', 'https://explorer.viabtc.com/btc'], 'reddit': ['https://reddit.com/r/bitcoin'], 'technical_doc': ['https://bitcoin.org/bitcoin.pdf'], 'source_code': ['https://github.com/bitcoin/'], 'announcement': []}, 'platform': None, 'date_added': '2013-04-28T00:00:00.000Z', 'twitter_username': '', 'is_hidden': 0}}}
I have tried the following without any success....
extracted_date = data_dict['data']['date_added']
In fact, my attempt returns the following error....
KeyError: 'date_added'
I do not understand why this error is occuring
CodePudding user response:
extracted_date = data_dict['data']['1']['date_added']
CodePudding user response:
You actually have a double nested dict. Inside 'data'
there is a dict named '1'
, in which the key 'date_added'
can be found.
Try:
extracted_date = data_dict['data']['1']['date_added']