Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug summary
When trying to input a dataframe to a table, it will raise keyerror. Since cellText [0] will not give the first row of the dataframe and thus not returning the correct column length. So, I made a modification to recognize cellText as dataframe.
contact:chenxuw@alumni.cmu.edu
Code for reproduction
df=pd.DataFrame()#any dataframetable=table.table(ax,df,loc='center')
Actual outcome
Traceback (most recent call last):
File "C:\Users\053232\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\indexes\base.py", line 3653, in get_loc
return self._engine.get_loc(casted_key)
File "pandas_libs\index.pyx", line 147, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\index.pyx", line 176, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\hashtable_class_helper.pxi", line 7080, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas_libs\hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 0
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "c:/Users/Downloads/suspension_check.py", line 147, in
generate_image(suspended_etfs,'suspended_etfs')
File "c:/Users/Downloads/suspension_check.py", line 106, in generate_image
tbl = table.table(ax, df, loc='center')
File "C:\Users\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\table.py", line 754, in table
cols = len(cellText[0])
File "C:\Users\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\frame.py", line 3761, ingetitem
indexer = self.columns.get_loc(key)
File "C:\Users\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\indexes\base.py", line 3655, in get_loc
raise KeyError(key) from err
KeyError: 0
Expected outcome
return a table contains a dataframe
Additional information
Check we have some cellText
if cellText is None: # assume just colours are needed rows = len(cellColours) cols = len(cellColours[0]) cellText = [[''] * cols] * rowselif isinstance(cellText, pd.DataFrame): # 获取DataFrame的列名 column_names = cellText.columns.values cellText = np.vstack([column_names, cellText.values])
Operating system
No response
Matplotlib Version
3.7.5
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
pip