社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

在Python中取消堆栈行标签(透视表)

MarthaF • 6 年前 • 1897 次点击  

我想使用Python取消对行标签名称的备份。

已清除数据以删除总计行和na行。

代码的外观:

Description   | Table    |  Chair
***Manila***  |          |   
Apple         |     1    |    3
Pair          |     0    |    1
Orange        |     1    |    0
Watermelon    |     0    |    5
Banana        |     0    |    7
***Quezon***  |          |  
DragonFruit   |     0    |    0
StarApple     |     0    |    0
Longan        |     0    |    1
Cherries      |     1    |    2
Mango         |     0    |    5

表格图像:

how raw data looks like

enter image description here

我希望代码看起来像:

Description  |   Day   |    Table  |  Chair
Manila    |    1     |     1    |   3
Manila    |    2     |     0    |   1
Manila    |    3     |     1    |   0
Manila    |    4     |     0    |   5
Manila    |    5     |     0    |   7
Quezon    |    1     |     0    |   0
Quezon    |    2     |     0    |   0
Quezon    |    3     |     0    |   1
Quezon    |    4     |     1    |   2
Quezon    |    5     |     0    |   5

表格图像: enter image description here

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/50697
文章 [ 2 ]  |  最新文章 6 年前