This community-built FAQ covers the “Inner Merge III” exercise from the lesson “Working with Multiple DataFrames”.
Paths and Courses
This exercise can be found in the following Codecademy content:
Data Science
Data Analysis with Pandas
FAQs on the exercise Inner Merge III
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
Need broader help or resources? Head here.
Looking for motivation to keep learning? Join our wider discussions.
Learn more about how to use this guide.
Found a bug? Report it!
Have a question about your account or billing? Reach out to our customer support team!
None of the above? Find out where to ask other questions here!
In this exercise they ask you to Merge all three DataFrames ( sales
, targets
, and men_women
) into one big DataFrame called all_data
.
My question is why do I have to use:
df1.merge(df2).merge(df3)
instead of:
all_data = pd.merge(sales,targets,men_women)
If I understand correctly you can only use pd.merge when you have 2 columns to merge and df1.merge when you have more than 2 to merge?
2 Likes
Guys I’m kind of lost here. In exercise 4 it says
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
.
How do I apply this ‘AND’ condition in order to obtain df ‘results’ ? Someone help me please.
6 Likes
I understand the concept- I need help with choosing the syntax…the code I wrote makes sense to me, but i doubt the syntax is correct. I wrote
results=all_data[(all_data.revenue > all_data.sales) AND (all_data.women > all_data.men)]
there’s no solution or hint button so I’m not sure- this site’s not free so they had better get back to me…
1 Like
Hi, I also had some trouble with this, you have to use “&”, not “AND”
3 Likes
The problem with this you are saying ‘all_data.sales’ it should be ‘all_data.target’ and you need to use a “&” . I do agree there should probably be a hint, but this an example of a working answer:
results = all_data[(all_data.revenue > all_data.target) & (all_data.women > all_data.men)]
2 Likes
Why are we let to guess the solution? There is not explanation. Feels awful
1 Like
thanks! it worked
They really should put a hint about the “&”
1 Like
Why do we not use .reset_index() when creating new dataframes using the .merge method?
1 Like
Hello,
I beleve it is because we use reset_index() when we are transforming series into data frames. When you groupby the dataframe, it makes it series and that’s why you are resetting the index to make it dataframe again.
However, you do not need to reset index I guess when you merge Data Frames becuase merged data frames are already data frames.
Best regards,
is there a way to display the stdout/terminal/console output of script.py instead of the rendered html file/table view of dataframes? i was wanting to debug my approach using DataFrame.apply()
instead of the indexing solution, but I can’t find any way to view my print statements
The same question as yours strikes me and after some research, here’s what I’ve learned:
pd.merge() methods accepts only 2 DataFrame as input.
That being said, while you can’t do pd.merge(DF1, DF2, DF3), you can do pd.merge(pd.merge(DF1, DF2), DF3)
hopefully this help you…