LIne By Line Explanation || Easy Solution Beginner Friendly || Pandas ||
Intuition\nThe problem seems to ask for a solution to pivot a given Pandas DataFrame named \'weather\'. The goal is to create a new DataFrame where the rows cor
# Intuition\nThe problem seems to ask for a solution to pivot a given Pandas DataFrame named \'weather\'. The goal is to create a new DataFrame where the rows correspond to months, the columns correspond to cities, and the values are the maximum temperatures for each combination of month and city.\n\n# Approach\nTo solve this problem, we can utilize the Pandas library in Python. We use the `.pivot_table()` function to pivot the \'weather\' DataFrame. We specify \'month\' as the index, \'city\' as the columns, \'temperature\' as the values, and \'max\' as the aggregation function to calculate the maximum temperature for each combination of month and city.\n\n# Complexity\n- Time complexity:\n  - The time complexity depends on the size of the \'weather\' DataFrame but can be considered as O(n), where n is the number of rows in the DataFrame.\n\n- Space complexity:\n  - The space complexity is O(n) because we create a new DataFrame in the pivoted format.\n\n# Code\n```python\nimport pandas as pd\n\ndef pivotTable(weather: pd.DataFrame) -> pd.DataFrame:\n    return weather.pivot_table(index=\'month\', columns=\'city\', values=\'temperature\', aggfunc=\'max\')\n
['Pandas']