I have a dictionary that's something like this.
d = {
"p1": ["$0.00", nan, "$25.00"],
"p2": ["$30.25", nan, "$12.25"],
"p3": ["$0.00"],
"p4": [nan, "$15.00"]
}
I'd like to look up values from the dictionary and assign them to a column in pandas DataFrame. The DataFrame is something like this:
df = pd.DataFrame({
'name': ["p1","p2","p3","p4"],
'val': [np.nan, np.nan, 4, np.nan]
})
Assignment:
def fun(name):
# look up from dict
# apply condition
return
df['val'] = df.apply(lambda x: func(x['name']), axis=1)
For the assignment, the condition is to find the largest value from the dictionary, if length of the value pair > 0, i.e there is more than 1 element in the list. Note, the elements are stored as strings. So, need the function needs to convert them to float type.
Expected output:
