【发布时间】:2020-03-09 14:23:32
【问题描述】:
您好,我想知道这段代码在复杂性符号 big O 上的表现如何,df1 有 ``N 行,df2 有 M 行,M << N。
var_ref 中的 Evry x 将在 set(df2.var0) 中搜索。这等于N*N == O(n^2) ??
df1['var1'] = df1['var_ref'].apply(lambda x: True if x in df2.var0.unique() else False) * 1
【问题讨论】:
-
在集合中搜索是恒定的,所以这应该是 O(MN)。既然你提到了 Mvar.unique()。
标签: python pandas performance lambda time-complexity