Selecting Rows from Dataframe

Hi,

I have a data set that consists of several variables observed for a number of subjects. However, instead of viewing the data across subjects to see how the variables change by subject, I want to look at each subject’s observed value.

For example, in one panel I have a single bar graph indicating a mortality probability for that selected individual; in another panel I have the individuals scores on 5 different dimensions, and on the final panel I have a box plot showing the individual’s scores compared to the population quartiles.

The challenge I’ve had is trying to understand how to select a different individual and trigger updates to each of those displays.

One approach I’ve taken is something like this:

user_number = 1
df2 = pd.read_csv('./data/data1.csv', index_col=0)
# Give more intuitive names to the columns
df2.columns = [u'Obs', u'sid', u'Disease1', u'Disease2', u'GT', u'ON', u'HI',
               u'MortalityProb', u'MD1', u'MD2', u'MD3', u'MD4', u'MD5']

data_as_dict = df2.to_dict('records')
data_source = ColumnDataSource(data=dict(source=data_as_dict))
user_row = {k: [v] for k, v in (data_as_dict[user_number-1]).items()}
user_source = ColumnDataSource(data=user_row)

patient_selector_callback = CustomJS(args=dict(user_data=user_source), code="""
var f = cb_obj.get(‘value’);
if (f != null) {
var r = data_set.get(‘data’);
var d = r[‘source’][f-1];
var u = user_data.get(‘data’);
for (var key in d){
u[key]=[d[key]];
}
user_data.trigger(‘change’);
}
“”")
patient_selector_callback.args[“data_set”] = data_source

_patients = [('Patient ’ + str§, str§) for p in patients]

d = Dropdown(label=“Select Patient”,
button_type=“default”,
menu=_patients,
width=180,
default_value=str(current_patient),
callback=patient_selector_callback)

# Box boundary
fillbox = fig.quad(top=1, bottom=0, left=-0.1, right=0.1, color="#EEEEEE")

# Box fill
boxfill = fig.quad(top='MortalityProb', bottom=0, left=-0.1, right=0.1, color=color2, source=user_source)



The above code isn't complete, but a selection of code to show an example of setting up the data sources - one is the full data set, the other is a single row of the data set. The idea is to use a DropDown (I couldn't get a selector to work) to select an individual by index, then copy that row of data into the user_source object, then trigger the change event, hopefully causing a replot of the different graphs that use that data source.

The problem I have at the moment is that I don't understand how to address a single value in a ColumnDataSource. I don't need but subsets of the rows. Even if I break up the data sources into sub groups of the columns, the values are used individually, not as a set of data points, which seems to be the model for most things (I think). At an extreme I could create a single data source per column of data but that really does seem extreme.

Thanks for any guidance - I've been working on trying to understand how to make this work for several days.

Cheers!

Ron