3

I'm attempting to use quantopian qgrid to print dataframes in iPython notebook. Simple example based on example notebook:

import qgrid
qgrid.nbinstall(overwrite=True)
qgrid.set_defaults(remote_js=True, precision=2)

from pandas import Timestamp
from pandas_datareader.data import get_data_yahoo

data = get_data_yahoo(symbols='SPY',
                      start=Timestamp('2014-01-01'),     
                      end=Timestamp('2016-01-01'),
                      adjust_price=True)

qgrid.show_grid(data, grid_options={'forceFitColumns': True})

Other than the precision args, how do you format the column data? It seems to be possible to pass in grid options like formatterFactory or defaultFormatter but unclear exactly how to use them for naive user.

Alternative approaches suggested in another question but I like the interaction the SlickGrid object provides.

Any help or suggestions much appreciated.

Community
  • 1
  • 1
user2579685
  • 319
  • 9
  • 19

2 Answers2

4

Short answer is that most grid options are passed through grid_options as a dictionary, eg:

grid_options requires a dictionary, eg for setting options for a specific grid:

qgrid.show_grid(data,
                grid_options={'fullWidthRows': True,
                              'syncColumnCellResize': True,
                              'forceFitColumns': True,
                              'rowHeight': 40,
                              'enableColumnReorder': True,
                              'enableTextSelectionOnCells': True,
                              'editable': True})

Please, see details here

tagoma
  • 3,896
  • 4
  • 38
  • 57
0

I changed the float format using df.round (would be useful change the format using the column_definitions).

Anyway the slider filter isn't in line with the values in the columns, why?

import pandas as pd 
import qgrid
import numpy as np 
col_def = { 'B': {"Slick.Editors.Float.DefaultDecimalPlaces":2}}
np.random.seed(25) 
df = pd.DataFrame(np.random.random([5, 4]), columns =["A", "B", "C", "D"]) 
df = df.round({"A":1, "B":2, "C":3, "D":4}) 
qgrid_widget = qgrid.show_grid(df, show_toolbar=True, column_definitions=col_def)
qgrid_widget

enter image description here

glima
  • 31
  • 1
  • 1
  • 2
  • Using the slider is indeed oftentimes very painful. It would be great to allow users to enter min and max value of the selected range – glima Oct 01 '20 at 11:27
  • I used also the parameter : precision (integer) – The number of digits of precision to display for floating-point values. If unset, we use the value of pandas.get_option(‘display.precision’). "qgrid.show_grid(df, show_toolbar=False, column_definitions=col_def, precision=1)". But I can't set the individual columns, right? – glima Oct 01 '20 at 12:23