Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 熊猫:如何返回不在另一个数据帧中的值列表?_Python_Pandas - Fatal编程技术网

Python 熊猫:如何返回不在另一个数据帧中的值列表?

Python 熊猫:如何返回不在另一个数据帧中的值列表?,python,pandas,Python,Pandas,上面是我的两个数据帧。我正在做一些数据分析,希望“名称”列中的值列表的“货币”不在另一个数据框中。我的预期输出如下。请建议 import pandas as pd df1 = pd.DataFrame({'name': ['CAD123', 'MXN789', 'EUR567','JPY224', 'EUR673', 'PLN254'], 'currency': ['CAD', 'MXN', 'EUR', 'JPY', 'EUR','PLN']}) df2 = pd.D

上面是我的两个数据帧。我正在做一些数据分析,希望“名称”列中的值列表的“货币”不在另一个数据框中。我的预期输出如下。请建议

import pandas as pd
df1 = pd.DataFrame({'name': ['CAD123', 'MXN789', 'EUR567','JPY224', 'EUR673', 'PLN254'], 
           'currency': ['CAD', 'MXN', 'EUR', 'JPY', 'EUR','PLN']})

df2 = pd.DataFrame({'currency':['EUR','PLN']})

我们使用
loc

Expected_list = ['CAD123','MXN789','JPY224']
您可以尝试以下方法:-

l = df1.loc[~df1.currency.isin(df2.currency), 'name'].tolist()
['CAD123', 'MXN789', 'JPY224']
输出:-

df1[~df1['currency'].isin(df2['currency'])]['name'].tolist()

请建议。有具体问题吗?你试过什么,做过什么研究吗?请看,再见。。快+1使用
.loc
和不使用
df1.name[~df1.currency.isin(df2.currency)].tolist()
?@TrentonMcKinney最好不要将片段链接起来~YOBEN\u感谢您的及时建议。我错过了~否定。
['CAD123', 'MXN789', 'JPY224']