for name,sub_group in op_train.groupby('UID'):
if sub_group['geo_code'].value_counts().isnull().any():
sub_group['geo_code'].fillna(-1,inplace=True)
else: sub_group['geo_code'].fillna(sub_group['geo_code'].value_counts[:1],inplace=True)
我要按用户名分组,然后计算用户名的geo_code
属性。如果为空,则用-1填充属性,否则它将用此列中最频繁出现的值填充,但是我发现这样做之后没有任何效果。我不知道为什么
此外,如果将value_counts[:1]
替换为index[0]
,它将返回错误IndexError: index 0 is out of bounds for axis 0 with size 0
。谁能帮我吗?