无法将数据帧系列转换为整数?

2024-06-01 21:40:47 发布

您现在位置:Python中文网/ 问答频道 /正文

全部。我有一个熊猫数据帧,它的结构如下:Pandas DataFrame

我想隔离行的子集,特别是那些属于某个坐标范围的行,我已经将其存储在列表中。这就是我目前正在处理的问题:

#create list of (putative?) exon coordinates
exonCoord = [(23114116, 23114327),(23117342,23117435),(23131892,23132007)]

#empty dataframe for only SNPs in coding regions
codingSNPs = pd.DataFrame(columns = ['pos','A','T','G','C','del','ins'])

for c in exonCoord:
    for idx,row in SNPs.iterrows():
        x = int(idx['pos'])
        if c[1] < x < c[0]:
            codingSNPs.append(idx,row)

在第x=int(idx['pos'])行中,我收到错误,“'int'对象不可下标。”将数据帧列转换为整数的最简单方法是什么?对于如何改进此代码的任何其他反馈,我们将不胜感激


Tags: 数据inposdataframepandas列表for结构