df= "start", "stop", "Seq"
50 121 aaaaaaaaaaaaabbbbbbbbbbbbcccccccccc...dddddd
25 150 aaaaahhhhhhhssssssssssssssccccccccc...dddddd
我需要使用结构切片(start=start,stop=stop)使用名为“start”和“stop”的列中的值作为start和stop值(对于数据帧的每一行)。你知道吗
我想使用def函数或lambda,但我得到了错误
def f(x,y,z):
return z.str.slice(start=x, stop=y)
df.apply(lambda x: f(x["start"],x["stop"],x["Seq"]))
输出: KeyError:('start','发生在索引id')
使用
.apply
对每行应用切片,格式为:string[start:stop]
如果要定义函数:
或者将
zip
与list comprehension
一起使用:使用的输入数据帧:
相关问题 更多 >
编程相关推荐