Python中文
首页
教程
问答
标签
搜索
登录
注册
减去pandas数据帧
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我有一个pandas数据框架(在Python 2.7中),具有时间和评级的两级索引,其期限和值是数据列:</p> <pre><code>Out[235]: Tenor Value Time Rating 2011-12-30 AAA 3M 0.343 AAA 6M 0.404 AAA 1Y 0.541 AAA 2Y 0.684 AAA 3Y 0.869 AAA 4Y 1.254 AAA 5Y 1.467 AAA 7Y 2.051 AAA 8Y 2.272 AAA 9Y 2.575 AAA 10Y 2.938 AAA 15Y 3.757 AAA 20Y 4.108 AAA 30Y 4.377 AA 3M 0.435 AA 6M 0.547 AA 1Y 0.620 AA 2Y 0.737 AA 3Y 0.925 AA 4Y 1.321 AA 5Y 1.545 AA 7Y 2.132 AA 8Y 2.420 AA 9Y 2.628 AA 10Y 3.108 AA 15Y 3.920 AA 20Y 4.219 AA 30Y 4.490 </code></pre> <p>我有另一个数据帧</p> ^{pr2}$ <p>我需要从每个多索引级别中减去<code>treasDF</code>,我该怎么做?我尝试了所有类型的<code>groupby</code>,但是失败了,比如。 <code>ratesDF.groupby(level=1).sub(treasDF.iloc[:,0], level=1)</code></p> <p>谢谢。在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>我想您不需要<code>groupby</code>,下面的代码能解决您的问题吗?在</p> <pre><code>ratesDF.Value - treasDF[ratesDF.Tenor].values </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
Python猜字gam
4 回答
Python猜字游戏
5 回答
Python猜字游戏?
5 回答
Python猜字游戏不会在玩家猜测所有字母时结束
7 回答
Python猜字游戏在有重复字符的单词上失败
8 回答
Python猜想
4 回答
Python猜数字游戏,而循环没有响应
4 回答
python猜测gam的代码反馈
10 回答
python猜测gam的变量问题
4 回答
python猜测具体路径?
7 回答
Python猜测我的号码(反向号码猜测)UnboundLocalE
10 回答
python猜测该数字在猜测过度后再试一次
1 回答
Python猜猜单词游戏bug
1 回答
Python猜猜游戏如何再现
4 回答
Python猜猜游戏服务器
8 回答
Python猜猜谁的游戏我没有得到我预期的输出
6 回答
Python猜谜游戏
9 回答
Python猜谜游戏,值错误:randrange()的空范围
4 回答
Python猜谜游戏,带尝试选项
3 回答
Python猜谜游戏,我的赢的条件打印赢和输
4 回答