本文介绍了基于两个 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 列创建一系列浮点值
发布评论