mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			60 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<pre>
 | 
						|
DataFrame <code>df1</code>
 | 
						|
+-------------+--------+
 | 
						|
| Column Name | Type   |
 | 
						|
+-------------+--------+
 | 
						|
| student_id  | int    |
 | 
						|
| name        | object |
 | 
						|
| age         | int    |
 | 
						|
+-------------+--------+
 | 
						|
 | 
						|
DataFrame <code>df2</code>
 | 
						|
+-------------+--------+
 | 
						|
| Column Name | Type   |
 | 
						|
+-------------+--------+
 | 
						|
| student_id  | int    |
 | 
						|
| name        | object |
 | 
						|
| age         | int    |
 | 
						|
+-------------+--------+
 | 
						|
 | 
						|
</pre>
 | 
						|
 | 
						|
<p>Write a solution to concatenate these two DataFrames <strong>vertically</strong> into one DataFrame.</p>
 | 
						|
 | 
						|
<p>The result format is in the following example.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:
 | 
						|
df1</strong>
 | 
						|
+------------+---------+-----+
 | 
						|
| student_id | name    | age |
 | 
						|
+------------+---------+-----+
 | 
						|
| 1          | Mason   | 8   |
 | 
						|
| 2          | Ava     | 6   |
 | 
						|
| 3          | Taylor  | 15  |
 | 
						|
| 4          | Georgia | 17  |
 | 
						|
+------------+---------+-----+
 | 
						|
<strong>df2
 | 
						|
</strong>+------------+------+-----+
 | 
						|
| student_id | name | age |
 | 
						|
+------------+------+-----+
 | 
						|
| 5          | Leo  | 7   |
 | 
						|
| 6          | Alex | 7   |
 | 
						|
+------------+------+-----+
 | 
						|
<strong>Output:</strong>
 | 
						|
+------------+---------+-----+
 | 
						|
| student_id | name    | age |
 | 
						|
+------------+---------+-----+
 | 
						|
| 1          | Mason   | 8   |
 | 
						|
| 2          | Ava     | 6   |
 | 
						|
| 3          | Taylor  | 15  |
 | 
						|
| 4          | Georgia | 17  |
 | 
						|
| 5          | Leo     | 7   |
 | 
						|
| 6          | Alex    | 7   |
 | 
						|
+------------+---------+-----+
 | 
						|
<strong>Explanation:
 | 
						|
</strong>The two DataFramess are stacked vertically, and their rows are combined.</pre>
 |