如何将另一列的值用作DF的参数
函数换档的参数,
我想将“换档”列的值作为我尝试使用的
df['gg_shift']=df['gg'].shift(df['shift'])
不起作用
但预期结果表
gg bool shift gg_shift
0.88 FALSE 0
0.87 TRUE 0
0.94 FALSE 1 0.87
0.17 FALSE 2 0.87
0.92 TRUE 0
0.51 FALSE 1 0.92
0.1 TRUE 0
0.88 FALSE 1 0.1
0.36 FALSE 2 0.1
0.14 TRUE 0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可能会误解您的逻辑,但是看起来您想获得所有false的
gg
值。如果是这种情况,则不需要使用
数据:
shift
列,只需ffill
和输出:
I might be misinterpreting your logic, but it looks like you want to get the
gg
values of the previous True for all False.If this is the case you do not need to use the
shift
column, simplyffill
andmask
the data:output:
因为只有标量可以传递给 获取
shift> shift> shift
没有0
的唯一值(否移位),仅分配匹配条件:Because only scalar is possible pass to
Series.shift
get unique values ofshift
without0
(no shift) and assign only match condition: