From the course: Python Functions for Data Science
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Combine data from pandas objects
From the course: Python Functions for Data Science
Combine data from pandas objects
In data analysis, you'll often work with data that’s split across multiple tables or files. Combining these tables is an essential step towards creating a complete dataset that supports deeper insights. In this lesson, you'll learn two main ways to combine Pandas DataFrames. The first is merging, which combines data based on matching keys or columns. The second is concatenating, which stacks or joins DataFrames together. Start by importing Pandas and creating two small DataFrames to work with. Check out both to confirm what they look like. Merging is used to combine two DataFrames based on shared column values, similar to performing a join in SQL. In this case, both DataFrames have a column named Name, so that will be the key for the merge. Here I've called pd.merge() and passed in scores followed by hours followed by on=”Name”. I've saved the resulting DataFrame in a variable named “merged”. Check out the result. This merges the two DataFrames side by side, aligning rows where the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.