如果性能不是一个大问题,您可以编写一个按行方法返回出现多次的值:def appear_more_than_once(s): cnt = s.value_counts() if len(cnt) > 0 and cnt.iloc[0] > 1: return cnt.index[0] else: return '-' df['Result'] = df.apply(appear_more_than_once, axis=1)print(df)# col1 col2 col3 Result#0 A A B A#1 A B B B#2 A B C -https://uscript.co/public/Google_108617488638529745626/python/4e5d36bc.py
添加回答
举报
0/150
提交
取消