Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to pivot a dat
#1
All,
I would like to pivot a data frame similar to the following SQL operation. Any help/guidance is appreciated:

# SQL Code - https://www.sqlshack.com/static-and-dynamic-sql-pivot-and-unpivot-relational-operator-overview/
SELECT * FROM 
(
SELECT YEAR(SOH.OrderDate) as SalesYear,
        SOH.SubTotal as TotalSales
 FROM sales.SalesOrderHeader SOH
     JOIN sales.SalesOrderDetail SOD ON SOH.SalesOrderId = SOD.SalesOrderId
) AS Sales
PIVOT (SUM(TotalSales)
FOR SalesYear IN ([2011],[2012],[2013],[2014]))
as PVT
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need Help! Pandas EXCEL PIVOT psb3958 1 943 Nov-13-2022, 10:37 PM
Last Post: deanhystad
  group by create pivot table python dawid294 1 1,284 Jun-22-2022, 06:13 PM
Last Post: Larz60+
  SQL Pivot EAV Quentin 2 2,814 Dec-03-2019, 11:52 PM
Last Post: Quentin
  pivot error shyamdba 1 2,442 Feb-02-2018, 11:12 PM
Last Post: klllmmm
  Should it be pivot or unstack for this sample shyamdba 0 2,109 Feb-02-2018, 05:50 PM
Last Post: shyamdba

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020