mwouts / itables

Pandas DataFrames as Interactive DataTables
https://mwouts.github.io/itables/
MIT License
730 stars 54 forks source link

DataTables warning: Requested unknown parameter '3' for row 0, column 3 #141

Closed mwouts closed 1 year ago

mwouts commented 1 year ago

With itables==1.3.5, displaying the following dataframe causes an HTML popup/warning:

DataTables warning: table id=a75598ce-5188-4faa-a80e-a0891dad1a25 - Requested unknown parameter '3' for row 0, column 3. For more information about this error, please see http://datatables.net/tn/4

import pandas as pd

df = pd.DataFrame({'a':[1, 2]}, index=pd.Index([1,2], name='index'))
df.columns.name = 'columns'
df.T.reset_index()

And indeed the data in the table is not right (the content in the rows are shifted to the left) image

vs image

mwouts commented 1 year ago

A simpler example is a dataframe that has a name for the column index, but no name on the row index:

pd.DataFrame({'a':[1]}).rename_axis('columns', axis=1)

The HTML representation of the table looks like this: image

Because of the name on the column index, the HTML header of the table has two entries, which is inconsistent with the table data that has just one entry. This causes a problem for itables.show because that function uses the same HTML header as Pandas, but drops the index when the index is not informative (here it removes the 0).