【发布时间】:2018-12-18 07:26:32
【问题描述】:
我有一个正在读取的 csv 文件,我有一列数字字符串,我正在尝试获取后续两行之间的差异。这些数字在值后面带有“ft”的深度(例如 4.23 英尺),我能够摆脱“ft”(例如 4.230),但不知道如何分配这些值,所以我可以算一下。
depth = float(depth)
rate=0
'''Need to find a way to subtract next line from current line to find
rate of change over 15 minute period'''
for i, data in enumerate(depth):
d1=i
d2=i+1
while rate == 0:
rate = d1-d2
print(rate)
这给了我一个“'float' object is not iterable”的 TypeError。 当我注释掉“depth = float(depth)”行时,我只得到 -1 值,我理解那里的问题。
first few lines of raw data first few lines of result data
第二行第一个值减去第二个值等于第三行第一个值。
【问题讨论】:
-
在运行此代码之前,
depth中有什么内容? (Edit 这个问题,请。“我的数据”或“csv 中的某些行”对我们没有帮助。)
标签: python-3.x