Reputation: 429
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.
Upvotes: 3
Views: 10082
Reputation: 41
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
Upvotes: 0
Reputation: 4060
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
Upvotes: 4