我已经使用了“ for”循环,这花了很多时间,并且写了用户 为无法应用的“应用”功能定义的功能。
for i in range(0,train_merchant_info.shape[0]):
for j in range(0,country_ip.shape[0]):
if train_merchant_info["IP_Address"]
[i]>=country_ip["lower_bound_ip_address"][j] and
train_merchant_info["IP_Address"][i] <=
country_ip["upper_bound_ip_address"][j]:
train_merchant_info["Country"][i] = country_ip["country"][j]
else:
train_merchant_info["Country"][i] = "None"
下面是上述“ for”循环的“应用”功能
def add_country(x):
train_country = country_ip.apply(lambda y: y["country"] if
(x["IP_Address"]>= y["lower_bound_ip_address"]
and x["IP_Address"] <= y["upper_bound_ip_address"])else
None,axis=1)
return train_country
train_merchant_info["Country"] = train_merchant_info.apply(lambda x:
add_country(x),axis=1)
对于“应用”这是我得到的错误:
Wrong number of items passed 235, placement implies 1