Using ".pivot()"
IntuitionThe main intuition behind using the pivot method is to reshape a DataFrame from a long format to a wide format. In the context of the weather data, whe
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The main intuition behind using the pivot method is to reshape a DataFrame from a long format to a wide format. In the context of the weather data, where you have multiple rows representing temperatures for different cities across various months, pivoting allows you to:
- Organize the data so that each month corresponds to a single row.
- Create separate columns for each city, allowing for easy comparison of temperatures across cities for each month.

This makes the data easier to read and analyze, especially when you want to compare values across different categories (in this case, cities) for the same attribute (temperature).

# Approach
<!-- Describe your approach to solving the problem. -->
The approach involves the following steps:
1. Define the Function: Create a function named pivotTable that takes a pandas DataFrame (weather) as input.
2. Pivot the DataFrame: Use the .pivot method on the DataFrame:
- Set index='month' to make months the rows of the new DataFrame.
- Set columns='city' to create a column for each city.
- Set values='temperature' to fill the new DataFrame with temperature values.
3. Return the Result: The function returns the newly pivoted DataFrame.

# Complexity
- Time complexity: O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ --> where n is the number of rows in the original DataFrame. This is because each row needs to be processed to build the new DataFrame.

- Space complexity: O(m * c)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
The space complexity depends on the number of unique values in the month and city columns. If there are m unique months and c unique cities, the space required for the new DataFrame would be O(m * c) due to the creation of a new DataFrame with m rows and c columns.

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

def pivotTable(weather: pd.DataFrame) -> pd.DataFrame:
    return weather.pivot(index='month', columns='city', values='temperature')
    
```
['Pandas']