Revisit Combining Data Using concat()
You’ve made it to the end of section two, which was about combining data using
pd.concat(). Before I let you pass on to section three, let’s do a quick recap on what you learned in this section.
A default call of
pd.concat() works by passing, for example, two DataFrame objects into an iterable—this could be a list—and you did that using the
veggies DataFrame that you defined at the beginning of this course. Now, the first optional argument that you explored was the
axis argument that has a default of
"rows", but you also learned about how the concatenation works differently when you pass the string
"columns" instead. The next argument you explored was
keys, which by default is
None, but you can pass an iterable in here that then defines the multi-index labels that your DataFrame is going to get. As an example, this could be the names of the DataFrames that you’re using.
So you tried it out using
The next argument that you explored was
ignore_index, which by default is
False, but you can also pass the alternative value of
True, which has the effect that pandas ignores the index of the DataFrames that you concatenated and just builds a new zero-based index for the resulting DataFrame. And finally, you explored the
join keyword argument that has a default value of
And you took a look both visually as well as by running the code of what happens when you instead perform inner joins by passing the string
"inner" to the
pd.concat() has a couple more keyword arguments that you can pass, and I would suggest that you look at the documentation of
pd.concat(), for example passing it to the
help function or looking online in the pandas documentation.
Go ahead and explore some other things that you can do. However, you probably covered the most important keyword arguments in this section of the course. And with that, you’re ready to move on to learn about how you can combine data using
merge(), which is based on using join logic instead of just plain concatenation. You already got a bit of an experience of what the join logic does with the
join parameter on
concat(), but you will see that the results when using
merge() are going to be quite different than when using
Become a Member to join the conversation.