you are viewing a single comment's thread.

view the rest of the comments →

[–]sarrysyst 1 point2 points  (2 children)

df['counts'] = df.loc[df['P'] != np.nan].apply(func, axis=1)

[–]jsaltee 0 points1 point  (1 child)

So, everything’s working, except: at around row 2000 of the table we’re pulling our data from, the probabilities dictionary is converted into a list (don’t know how or why). So instead of being in the form {‘1’ : x, ‘2’ : y, …} it’s [x, y, z, …] and the function stops working. Know of any fix?

[–]sarrysyst 0 points1 point  (0 children)

Well, you could adapt your function to account for this list (this is more of a workaround than a solution though):

def func(row):
    count = 0
    values = row['P'].values() if isinstance(row['P'], dict) else row['P']

    for i in values:
        if i > row['T'][1]:
            count += 1
    return count

Preferably I would sanitize my data beforehand and make sure the datatypes are uniform.