mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			45 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<pre>
 | 
						|
DataFrame <code>report</code>
 | 
						|
+-------------+--------+
 | 
						|
| Column Name | Type   |
 | 
						|
+-------------+--------+
 | 
						|
| product     | object |
 | 
						|
| quarter_1   | int    |
 | 
						|
| quarter_2   | int    |
 | 
						|
| quarter_3   | int    |
 | 
						|
| quarter_4   | int    |
 | 
						|
+-------------+--------+
 | 
						|
</pre>
 | 
						|
 | 
						|
<p>Write a solution to <strong>reshape</strong> the data so that each row represents sales data for a product in a specific quarter.</p>
 | 
						|
 | 
						|
<p>The result format is in the following example.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:
 | 
						|
</strong>+-------------+-----------+-----------+-----------+-----------+
 | 
						|
| product     | quarter_1 | quarter_2 | quarter_3 | quarter_4 |
 | 
						|
+-------------+-----------+-----------+-----------+-----------+
 | 
						|
| Umbrella    | 417       | 224       | 379       | 611       |
 | 
						|
| SleepingBag | 800       | 936       | 93        | 875       |
 | 
						|
+-------------+-----------+-----------+-----------+-----------+
 | 
						|
<strong>Output:</strong>
 | 
						|
+-------------+-----------+-------+
 | 
						|
| product     | quarter   | sales |
 | 
						|
+-------------+-----------+-------+
 | 
						|
| Umbrella    | quarter_1 | 417   |
 | 
						|
| SleepingBag | quarter_1 | 800   |
 | 
						|
| Umbrella    | quarter_2 | 224   |
 | 
						|
| SleepingBag | quarter_2 | 936   |
 | 
						|
| Umbrella    | quarter_3 | 379   |
 | 
						|
| SleepingBag | quarter_3 | 93    |
 | 
						|
| Umbrella    | quarter_4 | 611   |
 | 
						|
| SleepingBag | quarter_4 | 875   |
 | 
						|
+-------------+-----------+-------+
 | 
						|
<strong>Explanation:</strong>
 | 
						|
The DataFrame is reshaped from wide to long format. Each row represents the sales of a product in a quarter.
 | 
						|
</pre>
 |