Python中文
首页
教程
问答
标签
搜索
登录
注册
如何将数据帧行转换为标题?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我在151个不同的数据帧中有一些关于前151个口袋妖怪的数据</p> <pre><code> id identifier pokemon_id stat_id base_stat local_language_id name 36 7 Squirtle 7 1 44 9 HP 37 7 Squirtle 7 2 48 9 Attack 38 7 Squirtle 7 3 65 9 Defense 39 7 Squirtle 7 4 50 9 Special Attack 40 7 Squirtle 7 5 64 9 Special Defense 41 7 Squirtle 7 6 43 9 Speed id identifier pokemon_id stat_id base_stat local_language_id name 18 4 Charmander 4 1 39 9 HP 19 4 Charmander 4 2 52 9 Attack 20 4 Charmander 4 3 43 9 Defense 21 4 Charmander 4 4 60 9 Special Attack 22 4 Charmander 4 5 50 9 Special Defense 23 4 Charmander 4 6 65 9 Speed </code></pre> <p>我真正想要的是每个pokemon一行,每个stat作为新数据帧的一列。像这样的</p> <pre><code>id identifier pokemon_id HP Attack ... 4 Charmander 4 39 52 ... 7 Squirtle 7 44 48 ... </code></pre> <p>有没有一种简单的方法可以用熊猫数据帧来实现这一点</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>我相信这会满足你的要求:</p> <pre><code>df.groupby(['id', 'identifier', 'name']).base_stat.first().unstack('name') </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
VirtualEnvRapper错误:路径python2(来自python=python2)不存在
8 回答
virtualenvs上的pyinstaller,没有名为导入错误的模块
1 回答
virtualenvs是否可以退回到用户包而不是系统包?
9 回答
virtualenvwrapper CentOS7
3 回答
virtualenvwrapper IOError:[Errno 13]权限被拒绝
3 回答
virtualenvwrapper mkproject和shell在windows中的启动问题?
4 回答
virtualenvwrapper mkvirtualenv不工作但没有错误
5 回答
Virtualenvwrapper python bash
7 回答
virtualenvwrapper:“workon”何时更改到项目目录?
7 回答
virtualenvwrapper:mkvirtualenv可以工作,但是rmvirtualenv返回bash:没有这样的文件或目录
9 回答
virtualenvwrapper:virtualenv信息存储在哪里?
6 回答
virtualenvwrapper:命令“python设置.pyegg_info“失败,错误代码为1
6 回答
virtualenvwrapper:如何将mkvirtualenv的默认Python版本/路径更改为ins
7 回答
Virtualenvwrapper:模块“pkg_resources”没有属性“iter_entry_points”
6 回答
Virtualenvwrapper:没有名为virtualenvwrapp的模块
5 回答
Virtualenvwrapper.bash_profi的正确设置
3 回答
Virtualenvwrapper.hook:权限被拒绝
9 回答
virtualenvwrapper.sh:fork:资源暂时不可用Python/Djang
3 回答
Virtualenvwrapper.shlssitepackages命令不工作
4 回答
Virtualenvwrapper.sh函数在bash sh中不可用
7 回答