Skip to Content
Learn
Working with Multiple DataFrames
Inner Merge III

In addition to using pd.merge, each DataFrame has its own merge method. For instance, if you wanted to merge orders with customers, you could use:

new_df = orders.merge(customers)

This produces the same DataFrame as if we had called pd.merge(orders, customers).

We generally use this when we are joining more than two DataFrames together because we can “chain” the commands. The following command would merge orders to customers, and then the resulting DataFrame to products:

big_df = orders.merge(customers)\ .merge(products)

Instructions

1.

We have some more data from Cool T-Shirts Inc. The number of men’s and women’s t-shirts sold per month is in a file called men_women_sales.csv. Load this data into a DataFrame called men_women.

2.

Merge all three DataFrames (sales, targets, and men_women) into one big DataFrame called all_data.

3.

Display all_data using print.

4.

Cool T-Shirts Inc. thinks that they have more revenue in months where they sell more women’s t-shirts.

Select the rows of all_data where:

  • revenue is greater than target

AND

  • women is greater than men

Save your answer to the variable results.

Folder Icon

Sign up to start coding

Already have an account?