DDSA Solutions

2889. Reshape Data Pivot

Advertisement

About this solution

Reshape Data Pivot is a unknown-difficulty LeetCode problem covering the Database pattern. The Python solution below uses an idiomatic approach that is clean, readable, and directly submittable on LeetCode. Study the logic carefully — recognising the underlying pattern is the key skill that transfers to similar problems in interviews.

Key Techniques

2889.py
Python
import pandas as pd

def pivotTable(weather: pd.DataFrame) -> pd.DataFrame:
    return weather.pivot_table(
      index='month',
      columns='city',
      values='temperature',
      aggfunc='max',
    )
Advertisement
Was this solution helpful?