数据框熊猫之间的匹配索引

时间:2019-06-12 10:55:15

标签: python pandas

我要操纵df2

df1=pd.DataFrame({'Names':['a','c']})
df2=pd.DataFrame({'Names':['a','b','c','d'], 'Text':['bla','hello','hi','today']})

在两个dfs中,“名称”均设置为索引。 我想对df2进行操作,使其仅包含

a bla
c hi

如果我正确理解了df.drop,它应该有点像(但对我而言似乎不合适)

for index,rows in df2.iterrows():
    df2.drop(df2[if df2.Names not in df1.Names ].index, inplace = True)

但这会在'if'上产生无效的语法 如果我将其删除,则会得到:

  

'Series'对象是可变的,因此不能被散列

0 个答案:

没有答案
相关问题