基于两个 Pandas 列创建一系列浮点值

编程入门 行业动态 更新时间:2024-10-28 06:26:02
本文介绍了基于两个 Pandas 列创建一系列浮点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下数据集

x y 0 0.5 1.5 1 2.5 3.5 2 1.5 2.5 3 4.5 5.5

我想生成一个数字范围从 x 到 y 的列,步长为 0.5....

i would like to generate a column with the range of numbers from x to y with a step of 0.5....

x y range 0 0.5 1.5 [0.5, 1.0, 1.5] 1 2.5 3.5 [2.5, 3.0, 3.5] 2 1.5 2.5 [1.5, 2.0, 2.5] 3 4.5 5.5 [4.5, 5.0, 5.5]

我该怎么做?

推荐答案

有可能,但如果性能很重要,那就不是 好主意:

It is possible, but if performance is important, it is not good idea:

df['range'] = [np.arange(s, e + .5, .5) for s, e in zip(df['x'], df['y'])] print (df) x y range 0 0.5 1.5 [0.5, 1.0, 1.5] 1 2.5 3.5 [2.5, 3.0, 3.5] 2 1.5 2.5 [1.5, 2.0, 2.5] 3 4.5 5.5 [4.5, 5.0, 5.5]

更多推荐

基于两个 Pandas 列创建一系列浮点值

本文发布于:2023-11-22 00:39:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615302.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:浮点   两个   系列   Pandas

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!