Uploaded September 2026 | Updated September 2026, 12 hours ago
Learn Python in Excel: xelplus.com/course/python-in-excel
Sales data split across monthly columns? Here's how to reshape it into one clean table, with month, sales, and units each in their own column, using Python inside Excel.
=PY
pd.wide_to_long(sales_data, stubnames=["sales","units"], i="sales rep", j="month", sep="_", suffix=".+").reset_index()
- Type =PY and press Tab to activate Python mode
- wide_to_long turns repeated column groups (like sales_Jan, units_Jan) into rows
- stubnames lists the values you're tracking
- i is your identifier column, like sales rep
- j names the new column that holds the month
- sep matches the separator in your source headers
- suffix=".+" means the leftover text can be anything
- reset_index() keeps everything aligned
- Right-click the Python output and choose "Excel Value" to drop it into cells
Add a new month to your source data and the table updates on its own.
Uses the pandas wide_to_long function. Check the pandas docs for the full reference.
π¨ Subscribe to "Between the Sheets" newsletter to stay on top of office tips and Excel hacks: link.xelplus.com/yt-d-newsletter
π Join this channel to get access to perks:
youtube.com/channel/UCJtUOos_MwJa_Ewii-R3cJA/join
π² Letβs connect on social:
Instagram: instagram.com/lgharani
LinkedIn: linkedin.com/in/leilagharani
#Excel
Learn Python in Excel: xelplus.com/course/python-in-excel
Sales data split across monthly columns? Here's how to reshape it into one clean table, with month, sales, and units each in their own column, using Python inside Excel.
=PY
pd.wide_to_long(sales_data, stubnames=["sales","units"], i="sales rep", j="month", sep="_", suffix=".+").reset_index()
- Type =PY and press Tab to activate Python mode
- wide_to_long turns repeated column groups (like sales_Jan, units_Jan) into rows
- stubnames lists the values you're tracking
- i is your identifier column, like sales rep
- j names the new column that holds the month
- sep matches the separator in your source headers
- suffix=".+" means the leftover text can be anything
- reset_index() keeps everything aligned
- Right-click the Python output and choose "Excel Value" to drop it into cells
Add a new month to your source data and the table updates on its own.
Uses the pandas wide_to_long function. Check the pandas docs for the full reference.
π¨ Subscribe to "Between the Sheets" newsletter to stay on top of office tips and Excel hacks: link.xelplus.com/yt-d-newsletter
π Join this channel to get access to perks:
youtube.com/channel/UCJtUOos_MwJa_Ewii-R3cJA/join
π² Letβs connect on social:
Instagram: instagram.com/lgharani
LinkedIn: linkedin.com/in/leilagharani
#Excel










