社区所有版块导航
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 pandas中使用.pivot时出现语法错误

jason-hernandez-73 • 5 年前 • 137 次点击  

我查看了很多与pivot表相关的问题,但没有找到解决此特定问题的问题。我有一个这样的数据框:

Drug        Timepoint    Tumor Volume (mm3)
Capomulin   0             45.000000
            5             44.266086
            10            43.084291
            15            42.064317
            20            40.716325
... ... ...
Zoniferol   25            55.432935
            30            57.713531
            35            60.089372
            40            62.916692
            45            65.960888

我试着改变数据,使药物名称成为列标题,时间点成为新索引,肿瘤体积是值。我在网上查到的所有东西都告诉我要使用:

mean_tumor_volume_gp.pivot(index = "Timepoint",
                           columns = "Drug",
                           values = "Tumor Volume (mm3)")

但是,当我运行此单元格时,会收到错误消息:

KeyError                                  Traceback (most recent call last)
<ipython-input-15-788b92ba981e> in <module>
      2 mean_tumor_volume_gp.pivot(index = "Timepoint",
      3                             columns = "Drug",
----> 4                             values = "Tumor Volume (mm3)")
      5 

KeyError: 'Timepoint'

这怎么是一个关键错误?“时间点”键是原始DF中的一列。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/56793
 
137 次点击