Python:无法解压缩不可迭代的int对象

时间:2019-05-21 14:22:47

标签: python pandas data-science

我正在使用python的pandas模块读取一个.txt,其内容如下:

4.29999365676926    255.0
4.333326940930262   60.39473684210526
4.366660225091264   0.0
4.399993509252266   255.0
4.4333267934132685  0.0
4.46666007757427    0.0
4.499993361735272   0.0
4.533326645896274   255.0
4.566659930057276   0.0

现在,我想做的是:每当第二列包含的值大于或等于230时,保存索引(行号)。为什么这对我很重要?因为稍后,我想创建一个仅包含时间戳(.txt的第一列)的列表,该时间戳属于第二列的值大于等于230的行。另外,我在第二列上执行操作。

好吧,这有点难以解释,也许实际的代码有助于澄清问题:

import pandas as pd
from matplotlib import pyplot as plt 


VideoData = pd.read_csv('myFile.txt', sep='\t')
VideoPixelMean = VideoData.iloc[:,1].values.tolist() #this column contains the mean of the pixel intensities within a specified ROI
VideoPixelMean = [int(el) for el in VideoPixelMean]
VideoTimestamp = VideoData.iloc[:,0].values.tolist() #this column contains the time at which the mean of the pixel intensities within the ROI was calculated
VideoTimestamp = [int(el) for el in VideoTimestamp]

SpokeList = []
for idx,el in VideoPixelMean:
    if int(el) >= 230:   #I'm trying to detect the spokes of a wheel: whenever pixel intensities are >=230, there is a spoke within the ROI
        SpokeList.append(idx)

VideoVelocity = []
VelocityTime = []
for idx in range(0, len(SpokeList)):
    if idx == 0:
        VideoVelocity.append(0)
    else:
        framesPassed = SpokeList[idx] - SpokeList[idx-1]
        velocity = 2*np.pi/360 * 72 * 50 * framesPassed/30 #each wheel has 5 spokes (the angle between two spokes is 72°) and a radius of 50mm; fps = 30
        VideoVelocity.append(velocity)
        velocityTime = VideoTimestamp[idx]
        VelocityTime.append(velocityTime)

无论如何,我的代码的前5行是以这种方式修改的,因为我(仍然)收到错误:cannot unpack non-iterable int object对于我的第一个for循环。但是,为什么我的VideoPixelMean不可迭代?

有人可以帮忙吗?

0 个答案:

没有答案