我只想从 df2 中选择那些等于 python pandas 中 df1 的变量的列
df1
parameter (column name)
a
b
c
df2
w x a c z
3 1 5 6 1
5 67 4 3 56
8 12 6 1 23
我的预期输出是
a c
5 6
4 3
6 1
Use intersection or isin对于布尔掩码:
df3 = df2[df.columns.intersection(df1['parameter'])]
Or:
df3 = df2.loc[:, df.columns.isin(df1['parameter'])]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)