Black Lives Matter. Please consider donating to Black Girls Code today.

Best way to display orderbook data with timeseries component?

I have the following orderbook data in a pandas dataframe:

                 quantity     tradeType
costPerShareYes                        
0.59                  252   SELL NO (0)
0.58                  261   SELL NO (0)
0.57                  230   SELL NO (0)
0.56                  300   SELL NO (0)
0.55                  623   SELL NO (0)
0.54                  226   SELL NO (0)
0.53                  117   SELL NO (0)
0.52                  623   SELL NO (0)
0.51                 2411   SELL NO (0)
0.50                 5257   SELL NO (0)
0.49                 3521  SELL YES (1)
0.48                 2590  SELL YES (1)
0.47                 4898  SELL YES (1)
0.46                 2245  SELL YES (1)
0.45                  934  SELL YES (1)
0.44                 1088  SELL YES (1)
0.43                 1111  SELL YES (1)
0.42                 1905  SELL YES (1)
0.41                  326  SELL YES (1)
0.40                  288  SELL YES (1)

I also have a timeRetrieved column, which indicates the time this group of data was retrieved.

I want to display this in a table like this:

My questions are:

  1. What is the best way to transform this data so that there is a column for each tradeType value?, or is it better to just create two dataframes side by side with Sell Yes/Sell No options?

  2. Is it better to display this using a DataTable or a basic table?

  3. I want to be able to view this as a timeseries object, so I can move a slider back and say “what did the orderbook look like yesterday? two days ago? etc…” I didn’t see an example that shows a table being updated by a slider in the examples, but I don’t see any reason it can’t be done… Is it possible to do this?

Hi @BigSteak4,

  1. you can change the format of your datatable using df.pivot as follows
>>> import pandas as pd 
... data = {'cost':[1, 2, 3, 3.5, 6], 'buy':['YES', 'YES', 'NO', 'YES', 'NO']} 
... df = pd.DataFrame(data) 
... df                                                                                                                        
   cost  buy
0   1.0  YES
1   2.0  YES
2   3.0   NO
3   3.5  YES
4   6.0   NO
>>> df.pivot(columns='buy', values='cost')                                                                                    
buy   NO  YES
0    NaN  1.0
1    NaN  2.0
2    3.0  NaN
3    NaN  3.5
4    6.0  NaN
  1. For Dash applications, the DataTable offers more possibilities than the plotly trace, especially in terms of filters, search, edits etc. If you just want to display it then the plotly trace is fine as well.

  2. You can indeed write a callback which updates the data property of a DataTable when the slider is updated.