【发布时间】:2020-05-15 13:59:15
【问题描述】:
我有一个 csv 文件,我将其过滤为两列,其中一列有时间戳值,另一列是数字 我想创建一个循环遍历文件的行,以对第一列时间中同一秒内所有时间的第二列的值求和 我在处理时间和算法本身时遇到了问题 这是我的一项试验:
df=pd.DataFrame(data=Input_filtered) #This is a dataframe of the file with only the 2 columns
for i in range(0,Input_filtered_size,1):
row1, row2 = df.iloc[i], df.iloc[i+1]
if row2['Time'] - row1['Time'] <= 1: #Iam not sure if comparing the time difference with 1 is right or not
df.iloc[i] = (row2['Number of Samples'] + row1['Number of Samples'])
编辑:两列的示例
Time Length
11:53:59 1
11:53:59 2
11:53:59 3
11:53:59 4
11:53:59 5
11:54:00 6
11:54:00 7
11:54:00 8
11:54:00 9
等等 我需要做的是以秒为单位对所有具有相同时间的样本求和,因此建议的输出将是:
Time Length
11:53:59 15
11:54:00 30
【问题讨论】:
-
发布示例数据和预期输出
-
现在可以看到了
标签: python loops dataframe time