0

I would need help with task I have. I have 2 dataframes containing almost same information and one Dataframe has 2 more columns. I need to get all lines from one DataFrame (all columns) based on conditions from another DataFrame.

Here is example:

import pandas as pd

Data_Source = [['Jan', 38, "Karlova"], ['David', 37, "Mifkova"], ['Tomas', 36, "Svetla"], ['Jirka', 55, "Nerudova"]]
Source_df = pd.DataFrame(Data_Source, columns = ['Name', 'Age', "Address"])

Data_Compare = [['Tomas', 36], ['Jirka', 55]]
Compare_df = pd.DataFrame(Data_Compare, columns = ['Name', 'Age'])

print("Dataframe 1 -- \n")
print(Source_df)

print("-"*5)
print("Dataframe 2 -- \n")
print(Compare_df)

As result I should get Dataframe containing rows from "Source_df" which meet criteria from second Dataframe:

    Name  Age   Address
0  Tomas   36    Svetla
1  Jirka   55  Nerudova
Jan Vaško
  • 21
  • 4

0 Answers0