Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.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_Dataframe_Indexing - Fatal编程技术网

Python 如何使用另一个数据帧的多索引筛选一个数据帧的列

Python 如何使用另一个数据帧的多索引筛选一个数据帧的列,python,pandas,dataframe,indexing,Python,Pandas,Dataframe,Indexing,我应该如何获取一个数据帧的一组列,这些列获取另一个数据帧的另一组列中的值 基本上,我试图实现的目标如下: df.loc[ df[['c1','c2']].isin(df2.index), : ] = [1,2,3,4,5] 但是这个代码不起作用。我应该如何做到这一点?一种方法是确保将一个索引与另一个索引进行比较: df.loc[df.set_index(['c1','c2']).index.isin(df2.index), :] = [1,2,3,4,5] 只有在保证过滤5行的情况下,

我应该如何获取一个数据帧的一组列,这些列获取另一个数据帧的另一组列中的值

基本上,我试图实现的目标如下:

df.loc[  df[['c1','c2']].isin(df2.index),  :  ] = [1,2,3,4,5]

但是这个代码不起作用。我应该如何做到这一点?

一种方法是确保将一个索引与另一个索引进行比较:

df.loc[df.set_index(['c1','c2']).index.isin(df2.index), :] = [1,2,3,4,5]

只有在保证过滤5行的情况下,这才有效。

有没有通用的方法可以做到这一点?这是非常通用的。我不知道怎样才能使它更一般化。