Python 我想将数据帧转换为特定的格式化数据帧或列表列表

Python 我想将数据帧转换为特定的格式化数据帧或列表列表,python,Python,这是数据帧 Year Category Performance 2014 Sales 1000 2014 Expenses 400 2014 Profit 200 2015 Sales 1170 2015 Expenses 460 2015 Profit 250 2016 Sales 660 2016 Expens

这是数据帧

Year    Category    Performance
2014    Sales           1000
2014    Expenses        400
2014    Profit          200
2015    Sales           1170
2015    Expenses        460
2015    Profit          250
2016    Sales           660
2016    Expenses        1120
2016    Profit          300
这是预期的产出

 [          
          ['Year', 'Sales', 'Expenses', 'Profit'],          
          ['2014', 1000, 400, 200],         
          ['2015', 1170, 460, 250],         
          ['2016', 660, 1120, 300],                     
        ]           
或者你能帮我把这个数据框转换成这个

Year Sales Expenses Profit      
2014 1000  400       200        
2015 1170  460       250        
2016 660   1120      300

看起来像是重复的:只有代码的答案可能会有帮助,但如果你添加一些解释,99%的时候答案会更好。你能描述一下你的代码是如何帮助读者理解它的吗?@3limin4t0r我不认为一个简单的单行函数(我也不把
reset\u index()
算作真正的函数)需要解释。如果有人不理解某个函数,他可以简单地用谷歌搜索它。
df = pd.pivot_table(df, index='Year', columns='Category', values='Performence').reset_index()