提问人:David Jackson 提问时间:2/10/2020 最后编辑:David Jackson 更新时间:2/25/2020 访问量:45
在 python 中基于两个列范围值创建一个逗号分隔列
Creating a comma seperated column in python based on two column range values
问:
我需要创建一个新列,其值从column1值(开始)到column2(结束)值,间隔python 例如,我的间隔范围为 0 到 5 我的数据帧具有 column1 值(开始)3 和 column2 值(结束)50 我需要创建一个逗号分隔值为 3,4,5,0,1,2,3,4,5 的列。总计 50 个这样的值 我怎样才能创建它?
答:
0赞
trigonom
2/10/2020
#1
import itertools as it
l = [0,1,2,3,4,5]
first = 3
end = 50
col = []
c = it.cycle(l)
begin = next(c)
while begin != first:
begin = next(c)
col. append(begin)
for i in range(first,end-1):
col.append(next(c))
col出来了 [3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1]
评论