1

I have a Python dictionary with 3 keys which I created using the following code. the dictionary is very large - approximately 100,000 rows.

t1=list(zip(df.Col1, df.Col2,df.Col3))
d_dict= dict(list(zip(t1,df.Col4)))

I now have a separate dataframe which is also very large which has 3 columns which match the dictionary keys. I want to apply series.map(d_dict) to this in order to optimize some code. How can I do this?

I am currently using the following code which has errors on nan and takes a very long time

s1 = df2.apply(lambda x: d_dict[x.Col1,x.Col2,x.Col3], axis=1)
s1= df2.map(d_dict)

is the kind of code that I would be looking for

LLONDON
  • 11
  • 1
  • 2

1 Answers1

0

i solved this by converting the 3 keys into a text '1,0,1' and then making my dictinoary a text '1,0,1: 2341' and using series.map(dict) with the one key.

LLONDON
  • 11
  • 1
  • 2