Error KeyError: 'bt_Open' in "In [7]"
Closed this issue · 4 comments
Hi, thanks for the software but,
I'm getting an error that I can not solve or why i'm getting it
I'm already reinstall Pandas and matplotlib but I get the same error
What I'm missing? do you have something on you blog like stuff to install before start, actualy I dont find here references to you blog, only to other blogs.
anyway this is my error can you help me solving it?
When I run the In[7] I get this error
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
~/.local/lib/python3.5/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
3077 try:
-> 3078 return self._engine.get_loc(key)
3079 except KeyError:
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'bt_Open'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
<ipython-input-7-1d7320c9a250> in <module>()
8 ax2.set_xticks([datetime.date(i,j,1) for i in range(2013,2019) for j in [1,7]])
9 ax2.set_xticklabels([datetime.date(i,j,1).strftime('%b %Y') for i in range(2013,2019) for j in [1,7]])
---> 10 ax1.plot(bitcoin_market_info['Date'].astype(datetime.datetime),bitcoin_market_info['bt_Open'])
11 ax2.bar(bitcoin_market_info['Date'].astype(datetime.datetime).values, bitcoin_market_info['bt_Volume'].values)
12 fig.tight_layout()
~/.local/lib/python3.5/site-packages/pandas/core/frame.py in __getitem__(self, key)
2686 return self._getitem_multilevel(key)
2687 else:
-> 2688 return self._getitem_column(key)
2689
2690 def _getitem_column(self, key):
~/.local/lib/python3.5/site-packages/pandas/core/frame.py in _getitem_column(self, key)
2693 # get column
2694 if self.columns.is_unique:
-> 2695 return self._get_item_cache(key)
2696
2697 # duplicate columns & possible reduce dimensionality
~/.local/lib/python3.5/site-packages/pandas/core/generic.py in _get_item_cache(self, item)
2487 res = cache.get(item)
2488 if res is None:
-> 2489 values = self._data.get(item)
2490 res = self._box_item_values(item, values)
2491 cache[item] = res
~/.local/lib/python3.5/site-packages/pandas/core/internals.py in get(self, item, fastpath)
4113
4114 if not isna(item):
-> 4115 loc = self.items.get_loc(item)
4116 else:
4117 indexer = np.arange(len(self.items))[isna(self.items)]
~/.local/lib/python3.5/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
3078 return self._engine.get_loc(key)
3079 except KeyError:
-> 3080 return self._engine.get_loc(self._maybe_cast_indexer(key))
3081
3082 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'bt_Open'
I am having the same issue
To resolve this problem rename columns
For btc:
bitcoin_market_info = bitcoin_market_info.rename(columns={'bt_Open*': 'bt_Open', 'bt_Close**': 'bt_Close'})
and eth:
eth_market_info = eth_market_info.rename(columns={'eth_Open*': 'eth_Open', 'eth_Close**': 'eth_Close'})
thanks, I go try
Thanks to @M3tiii for the solution. If you're wondering what went wrong, coinmarketcap started adding asterisks to the Open and Close column names. I've fixed the notebook by removing all asterisks from the dataframe column names (which may make it slightly more robust if coinmarketcap decide to add even more asterisks). I'm going to close this issue, but thanks to everyone for pointing this out to me.