提问人:dublinduke 提问时间:5/8/2023 最后编辑:Nickdublinduke 更新时间:5/8/2023 访问量:25
Python pandas 操作
Python pandas operations
问:
我的数据帧是这样的:
df = pd.DataFrame({'A': ['absf123', 'absf123', 'absf123', 'sdf123', 'sdf123', 'sdf123', 'sdf123'], 'B': [[1, 2, 3], [4, 5, 6], [2], [12, 13, 14], [21, 22, 23], [18, 19, 20, 21], [9]]})
“C”列中的结果应为 。No,Yes,No,Yes,No,No,Yes
例如,逻辑如下:第一行应为“否”,因为值 2 出现在 absf123 的其他值中。我有 4lacs 行。
这是我的代码,但没有得到想要的结果
def is_subset_of_others(df):
grouped=see.groupby('A')
df['C']=False
for _,group in grouped:
alpha_positions=[set(row['B']) for _, row in group.iterrows()]
for i, row in group.iterrows():
is_subset=all(set(row['A']).issubset(set(other)) or set(row['B']) == set(other) for other in alpha_positions if other!= set(row['B']))
df.loc[i,'C']=is_subset
#df['result']=results
return df
答: 暂无答案
评论