I have two dataframe:
df1
Name Emp ID Total Salary A B C D E
0 Mike A001 25000 5000 15000 3000 4500 2000
df2(Here column names cannot be assigned )
[5000, 15000, 3000, 2000]
How can I compare both data frame and print the matching rows as below:
Result:
A - 5000 B - 15000 C - 3000 E - 2000
use the numpy array on df2
df1[['A', 'B', 'C', 'E']] == df2.values
A B C E
0 True True True True
try this.
df2.columns=['A','B','C','E']
df1[(df1[df2.columns]==df2.values).columns]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.