Python Tutorial: Concatenation
Key Takeaways
This video tutorial demonstrates how to join data using concatenation in Python with the pandas library, covering basic concatenation along rows and columns, and handling overlapping indexes.
Full Transcript
in this video you'll learn how to join data with concatenation you may recognize the term concatenate from the concatenate formula used in spreadsheets to combine text cells the concept in pandas is the same and when it's applied to data frames it's like copying and pasting in a spreadsheet or like gluing two pieces of wood together face to face in pandas we use the pandas concat function to concatenate data frames the function allows us to join two or more data frames along either rows or columns concatenate along rows is very useful when working with split data for instance reports are often produced annually with each year saved to a separate tab or file you can vertically stack one or more data frames like these using pandas concat the function will return a single data frame with data ordered by the order of the data frame names you supply such as DF 1 DF 2 and so on basic concatenation works best when each input data frame has separate values for the index such as game key in this example that way the resulting frame will still have an index of unique values also it's worth noting that the concat function includes all rows by default in other words it creates an outer join sometimes the input data frames have generic indexes that overlap like the row numbers in a spreadsheet this case often occurs when batch loading data into data frames without specifying a named index not to worry concatenate Uralla ignore index you can set its value to true and let pandas generate a new uniquely numbered index for the concatenated data frame you can also use concat when combining complementary data here you'll want to concatenate across columns which is like pasting tables side by side you'll need to tell pandas to join by column pandas refers to moving down rows as access equals 0 and across columns as XS equals 1 by specifying axis equals 1 in the concat statement we override the default behavior and join the columns it's worth noting that all columns from the data frames are included by default you may need to drop or rename columns before continuing it's now time to concatenate your knowledge and practice on some day
Original Description
Want to learn more? Take the full course at https://learn.datacamp.com/courses/pandas-joins-for-spreadsheet-users at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
In this video you'll learn how to join data with concatenation.
You may recognize the term concatenate from the 'concatenate' formula used in spreadsheets to combine text cells.
The concept in pandas is the same,
and when it's applied to data frames, it's like copying and pasting in a spreadsheet, or like gluing two pieces of wood together face-to-face.
In pandas we use the pandas-concat function to concatenate data frames. The function allows us to join two or more data frames along either rows or columns.
Concatenating along rows is very useful when working with split data. For instance, reports are often produced annually with each year saved to a separate tab or file.
You can vertically stack one or more data frames like these using pandas concat. The function will return a single data frame with data ordered by the order of the data frame names you supply, such as df1, df2, and so on.
Basic concatenation works best when each input data frame has separate values for the index, such as 'Game Key' in this example. That way the resulting frame will still have an index of unique values.
Also, it’s worth noting that the concat function includes all rows by default. In other words, it creates an 'outer join'.
Sometimes the input data frames have generic indexes that overlap, like the row numbers in a spreadsheet. This case often occurs when batch-loading data into data frames without specifying a named index.
Not to worry - concat has an optional parameter called ignore-index. You can set its value to true and let pandas generate a new uniquely numbered index for the concatenated data frame.
You can also use concat when combining complementary data.
Here you'll want to concatenate across columns, which is like pasting tables s
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from DataCamp · DataCamp · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
SQL Server Tutorial: Date manipulation
DataCamp
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
R Tutorial: Adding aesthetics to represent a variable
DataCamp
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
Python Tutorial: Preparation for modeling
DataCamp
Python Tutorial: Machine Learning modeling steps
DataCamp
R Tutorial: The prior model
DataCamp
R Tutorial: Data & the likelihood
DataCamp
R Tutorial: The posterior model
DataCamp
R Tutorial: An Introduction to plotly
DataCamp
R Tutorial: Plotting a single variable
DataCamp
R Tutorial: Bivariate graphics
DataCamp
Python Tutorial: Customer Segmentation in Python
DataCamp
Python Tutorial: Time cohorts
DataCamp
Python Tutorial: Calculate cohort metrics
DataCamp
Python Tutorial: Cohort analysis visualization
DataCamp
R Tutorial: Building Dashboards with flexdashboard
DataCamp
R Tutorial: Anatomy of a flexdashboard
DataCamp
R Tutorial: Layout basics
DataCamp
R Tutorial: Advanced layouts
DataCamp
Python Tutorial: Time Series Analysis in Python
DataCamp
Python Tutorial: Correlation of Two Time Series
DataCamp
Python Tutorial: Simple Linear Regressions
DataCamp
Python Tutorial: Autocorrelation
DataCamp
R Tutorial: The gapminder dataset
DataCamp
R Tutorial: The filter verb
DataCamp
R Tutorial: The arrange verb
DataCamp
R Tutorial: The mutate verb
DataCamp
R Tutorial: What is cluster analysis?
DataCamp
R Tutorial: Distance between two observations
DataCamp
R Tutorial: The importance of scale
DataCamp
R Tutorial: Measuring distance for categorical data
DataCamp
Python Tutorial: Plotting multiple graphs
DataCamp
Python Tutorial: Customizing axes
DataCamp
Python Tutorial: Legends, annotations, & styles
DataCamp
Python Tutorial: Introduction to iterators
DataCamp
Python Tutorial: Playing with iterators
DataCamp
Python Tutorial: Using iterators to load large files into memory
DataCamp
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
SQL Tutorial: Tables: At the core of every database
DataCamp
SQL Tutorial: Update your database as the structure changes
DataCamp
Python Tutorial: Classification-Tree Learning
DataCamp
Python Tutorial: Decision-Tree for Classification
DataCamp
Python Tutorial: Decision-Tree for Regression
DataCamp
Python Tutorial: Census Subject Tables
DataCamp
Python Tutorial: Census Geography
DataCamp
Python Tutorial: Using the Census API
DataCamp
R Tutorial: A/B Testing in R
DataCamp
R Tutorial: Baseline Conversion Rates
DataCamp
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
R Tutorial: Introduction to qualitative data
DataCamp
R Tutorial: Understanding your qualitative variables
DataCamp
R Tutorial: Making Better Plots
DataCamp
SQL Tutorial: OLTP and OLAP
DataCamp
SQL Tutorial: Storing data
DataCamp
SQL Tutorial: Database design
DataCamp
Python Tutorial: Introduction to spaCy
DataCamp
Python Tutorial: Statistical Models
DataCamp
Python Tutorial: Rule-based Matching
DataCamp
More on: AI Productivity Tools
View skill →
🎓
Tutor Explanation
DeepCamp AI