🚀 Python3: Pivot Table Transformation | 89.04% Runtime
IntuitionTo efficiently transform the given DataFrame, we need to reshape the data so that each city's temperature data is displayed as separate columns while k
# Intuition  
To efficiently transform the given DataFrame, we need to reshape the data so that each city's temperature data is displayed as separate columns while keeping months as the index. Using `pivot` or `unstack()` is the most natural way to achieve this since they allow us to efficiently reorganize the data without unnecessary computations.

# Approach  
1. **Set Multi-Index**: Convert `month` and `city` into a hierarchical index to structure the data.  
2. **Extract Temperature Values**: Select the `temperature` column to maintain focus on relevant data.  
3. **Unstack the Data**: Convert the `city` level of the index into column headers, making each city a distinct column.  
4. **This approach is efficient because**:  
   - Avoids unnecessary data duplication.  
   - Utilizes Pandas' optimized index operations.  
   - Ensures a well-structured output with minimal memory overhead.  

# Complexity  
- **Time complexity**: $$O(n)$$ where $$n$$ is the number of rows in the dataset, since setting the index and unstacking are linear operations.  
- **Space complexity**: $$O(km)$$ where $$k$$ is the number of unique months and $$m$$ is the number of unique cities, as we store the transformed DataFrame explicitly in memory.  

# Code  
```python3 []
import pandas as pd

def pivotTable(weather: pd.DataFrame) -> pd.DataFrame:
    return weather.set_index(['month', 'city'])['temperature'].unstack()
```
['Pandas']