[英]Is there a function to compare two DataFrames and output the different elements?
我正在尝试比较两个不同的 DataFrame 以检查 new_df 符号是否存在于 old_df 中,如果它不存在于 old_df 中,我想将 output 列在一个列表中。
代码如下所示:
old_df = pd.DataFrame({'symbol': ['A', 'B', 'C', 'D', 'E']})
new_df = pd.DataFrame({'symbol': ['C', 'A', 'B', 'F', 'H']})
我想要这样的 output:
['F','H']
isin()
作为掩码
old_df = pd.DataFrame({'symbol': ['A', 'B', 'C', 'D', 'E']})
new_df = pd.DataFrame({'symbol': ['C', 'A', 'B', 'F', 'H']})
new_df[~np.isin(new_df.values,old_df.values)].values
array([['F'],
['H']], dtype=object)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.