Python中文
首页
教程
问答
标签
搜索
登录
注册
Pandas Dataframes如何维护索引post a group by/aggregation操作?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>这应该很容易,但我却有一个令人惊讶的恼人的时间。下面的代码演示了如何执行Pandas groupby操作,以便可以按符号计算方差。不幸的是,aggregation命令似乎去掉了整数索引,所以我尝试创建一个新的整数列表,并将其作为列添加到表中,并设置为新索引。在</p> <pre><code>vardataframe = voldataframe.groupby('Symbol') vardataframe = vardataframe.aggregate(np.var) vardataframe['newindex']= np.arange(1,(len(vardataframe)+1)) vardataframe.set_index(['newindex']) vardataframe = vardataframe.ix[:,['newindex','Symbol','volatility']] </code></pre> <p>然而,结果如下vardataframe.head()结果,它没有正确地将表的索引从符号改回数值。当我尝试执行merge命令时,这会在一两行中伤害我。在</p> ^{pr2}$ <p>如您所见,上面的问题是现在有两个符号列,并且索引没有正确设置。我想做的是去掉第二个Symbol列,并使newindex成为新索引。有人知道我做错了什么吗?(也许是对ix命令的误解)。非常感谢!在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>不用手动创建新索引,只需使用。。。在</p> <pre><code>df = df.reset_index() </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在乒乓球比赛中预测球的轨迹,对于AI球拍预测?
1 回答
如何在乒乓球游戏中阻止球
9 回答
如何在乘法和模中不乘空间?
8 回答
如何在乘法和除以2个不同的数字之间进行交换?
2 回答
如何在也是数据一部分的单个字符上拆分大字符串
10 回答
如何在乾草堆中找到針,有更好的解決方案嗎?
7 回答
如何在事件wxWidgets中传递自定义数据
2 回答
如何在事件中使用lambda i=i?
2 回答
如何在事件中心只接收最近的数据
4 回答
如何在事件发生之前保持云函数运行?
7 回答
如何在事件发生后使页面重定向到同一页面
2 回答
如何在事件回调之间保持python生成器的状态
6 回答
如何在事件处理程序(pythonsocket、sphinx)中保留docstring
6 回答
如何在事件处理程序中更改wxRichTextCtrl的光标位置?
2 回答
如何在事件处理程序中访问外部对象?
2 回答
如何在事件循环中将协程打包为正常函数?
6 回答
如何在事件循环之外运行协同程序?
9 回答
如何在事件循环结束时为并发未来的所有线程调用类方法?
9 回答
如何在事件文件中只保留一份摘要?
4 回答
如何在事件模板中添加事件
9 回答