0

I am building a web application and I am showing a dataframe there using the DataTable function from bokeh. I am trying to have it that the last row is displayed first and vice versa (reversing the row order). I can do this to the dataframe using the df.iloc[::1] function, but when converting to a datatable, the rows aren't reversed like I want them to be. Any help?

The code (example):

    df = pd.read_csv(myfile.csv)
    df = df.iloc[::1]
    Columns = [TableColumn(field=Ci, title=Ci) for Ci in df.columns]
    table = DataTable(columns=Columns, source=ColumnDataSource(df))

1 Answers1

0

Short answer

You can revers the Columns variable, it is of type list.

table = DataTable(columns=Columns[::-1], source=ColumnDataSource(df))

Longer answer

Your implementation has one mistake which is not connected to the bokeh library. This line doesn't revers the order of your Dataframe. Please try it out yourself.

df = df.iloc[::1]

You should solve the problem at this point. One of many options is this.

df = df[reversed(df.columns)]

This also works if you want to define your own order.

df = df[['c', 'b', 'a']]
mosc9575
  • 5,618
  • 2
  • 9
  • 32