2888 Reshape Data: Concatenate
Last updated
Last updated
DataFrame df1
Column Name | Type |
---|---|
DataFrame df2
Column Name | Type |
---|---|
Write a solution to concatenate these two DataFrames vertically into one DataFrame.
The result format is in the following example.
For the whole problem statement, please refer here.
Use pandas to handle the data.
Concatenate the two DataFrames vertically.
Provide the concatenated DataFrame.
The resulting DataFrame should have the same columns as the input DataFrames.
Import Pandas
We start by importing the Pandas library, which provides data structures and operations for manipulating numerical tables and time series.
Define the Function
We define a function concatenateTables
that takes two arguments df1
and df2
, which are DataFrames to be concatenated.
Concatenating DataFrames
We use the pd.concat
function to concatenate the two DataFrames df1
and df2
vertically.
The ignore_index=True
argument is used to reset the index of the resulting DataFrame after concatenation.
Return the Result
We return the concatenated DataFrame that contains the data from both input DataFrames vertically.
student_id
int
name
object
age
int
student_id
int
name
object
age
int