Skip to content
Advertisement

How to compare differently transposed data in pandas or python

I am trying to compare or merge two different data sets and I am using pandas for that.

The challenge that I am facing is that data is spread across rows in the first data set (Data1) and the other data set (Data2) has the same data spread across columns, below are the screenshots.

  1. Screenshot 1st – This is Data1
  2. Screenshot 2nd – This is Data2

Also, I have attached the same Excel workbook here for your reference.

enter image description here

enter image description here

What I am trying to do is convert one of them to another format to match the dataset and perform the merge.

Note: Transpose is not helping me, since I need to do it for each department and transpose does put everything either in rows or columns including department, whereas I only want to transpose weekly data.

What is the best way to achieve this in Python?

Advertisement

Answer

One option to transform the second dataframe is with pivot_longer from pyjanitor:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement