0

I have one data frame with four columns. Two of these columns contain data from 2017 and other two columns contain data from 2018. Below you can see how is look my data :

import pandas as pd
import numpy as np

data = {
        'sales_2017': [100,20,300,500,200],
        'profit_2017': [20,10,30,50,20],
        'sales_2018': [200,900,500,200,100],
        'profit_2018': [20,90,50,20,10],
        }


df = pd.DataFrame(data, columns = ['sales_2017','profit_2017','sales_2018','profit_2018'])

So now I want to make a pivot table for further analysis and I want to have columns ordered separately by 'year', 'sales', and 'profit'. It is important to mention years must be ordered as in the pic below or in order words first 2017 and after 2018 and etc.

enter image description here

So can anybody help me how to solve this problem?

oda
  • 2,762
  • 2
  • 3
  • 18
silent_hunter
  • 1,301
  • 7
  • 20

0 Answers0