mwouts / itables

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

Unable to display unsorted dataframe #30

Closed schwabts closed 2 years ago

schwabts commented 2 years ago

Loading matrix data into a dataframe it automatically gets sorted when using itables. Of course, I'd use numpy when really working with matrices but I have already come across some (unsorted?) tables that were sorted by exotic orders for good reasons. (After all, every table is sorted even if the order is not obvious.)

It must be possible to turn the feature off.

Code:

from itables import init_notebook_mode
init_notebook_mode(all_interactive=True)

import pandas as pd

A = """\
0.9 2.3 3.4 0.8
5.1 1.2 2.3 4.3
2.1 4.3 0.8 1.0
0.2 0.1 0.9 2.1"""

df = pd.DataFrame([x.split(' ') for x in A.split('\n')])
df

Result:

0 | 1 | 2 | 3 -- | -- | -- | -- 0.2 | 0.1 | 0.9 | 2.1 0.9 | 2.3 | 3.4 | 0.8 2.1 | 4.3 | 0.8 | 1.0 5.1 | 1.2 | 2.3 | 4.3 **Expected:** 0 | 1 | 2 | 3 -- | -- | -- | -- 0.9 | 2.3 | 3.4 | 0.8 5.1 | 1.2 | 2.3 | 4.3 2.1 | 4.3 | 0.8 | 1.0 0.2 | 0.1 | 0.9 | 2.1
mwouts commented 2 years ago

Thanks @schwabts for the question, sorry I did not answer earlier.

The answer found at https://stackoverflow.com/questions/4964388/is-there-a-way-to-disable-initial-sorting-for-jquery-datatables seems to apply here as well. You just need to pass order = [] to the datatables library.

One way to do this is by using show

from itables import show
show(df, order=[])

and the other way is to use a global option:

import itables.options as opt
opt.order = []

See the screenshot below: image