2024-04-23 10:36:39 发布
网友
我有以下简单的数据帧
import pandas as pd df = pd.DataFrame({'column_a': ['a', 'b', 'c', 'd', 'e'], 'column_b': ['b', 'x', 'y', 'c', 'z']}) column_a column_b 0 a b 1 b x 2 c y 3 d c 4 e z
我要在两个列中显示的字符串:
谢谢
类似于Sandeep Kadapa的解决方案。(没有tolist和loc。)
tolist
loc
>>> tuple(df['column_a'][df['column_a'].isin(df['column_b'])]) ('b', 'c')
intersection
这概括了任意数量的列。在
set.intersection(*map(set, map(df.get, df))) {'b', 'c'}
使用python的set对象:
set
in_a = set(df.column_a) in_b = set(df.column_b) in_both = in_a.intersection(in_b)
类似于Sandeep Kadapa的解决方案。(没有
tolist
和loc
。)intersection
这概括了任意数量的列。在
使用python的
set
对象:相关问题 更多 >
编程相关推荐