使用带有多键字典的series.map

我有一个带3个键的Python字典,该字典是使用以下代码创建的。字典非常大-大约有100,000行。

1. received: OK
2. received: OK
3. received: OK
error "Operation canceled"
4 exception read_some: End of file
5. received: OK
6. received: OK
7. received: OK
error "Operation canceled"
8 exception read_some: End of file
error "Operation canceled"
9 exception read_some: End of file

我现在有一个单独的数据框,该数据框也很大,有3列与字典键匹配的列。我想对此应用series.map(d_dict)以便优化一些代码。我该怎么办?

我当前正在使用以下代码,该代码在nan上有错误,并且需要很长时间

t1=list(zip(df.Col1,df.Col2,df.Col3))
d_dict= dict(list(zip(t1,df.Col4)))
s1 = df2.apply(lambda x: d_dict[x.Col1,x.Col2,x.Col3],axis=1)

是我想要的那种代码

wsg19870213 回答:使用带有多键字典的series.map

我通过将3个键转换为文本“ 1,1”,然后将我的词典设为文本“ 1,1:2341”,并使用带有一个键的series.map(dict)解决了这一问题。
本文链接:https://www.f2er.com/3120580.html

大家都在问