i have a dictionary:
k_msc = {5.7:{50: 1 , 125: 0.5 ,200: 0.1}, 6.2:{50: 1 , 125: 0.5 ,200: 0.1}, 6.7:{50: 1 , 125: 0.5 ,200: 0.1}}
and a pandas data frame. like:
( Std pH nacl a2 a4 surfcov_msc amount_mp amount_a2 \
Run
1 10 6.2 125 0.6 1.0 0.90 0.030 0.10
2 21 6.2 50 1.0 0.7 0.90 0.005 0.25
3 25 6.2 125 0.6 0.7 0.45 0.005 0.40
4 20 5.7 125 1.0 0.7 0.00 0.030 0.10
5 13 6.2 200 1.0 1.0 0.00 0.005 0.25 `
i do want to access the values stored in k_msc depending on the values in the columns pH and nacl:
def get_dict(mydict,mylist):
a = list(zip( *[x for x in mylist ] ))
list_items = [mydict[ x[0] ][ x[1] ] for x in a]
return list_items
acces the values:
get_dict(k_msc, (df.pH, df.nacl))
This feels kind of odd. Is there an easier/clearer way ?