python - 访问 Pandas 系列
问题描述
我有 6 个 CSV 文件,每个文件有 5 列。其中一列是时间,其余的是电压响应。对于所有 6 个文件,我创建了一个循环来查找每个响应列中何时超过某个阈值。代码如下所示:
#import csv
dfs = [pd.read_csv(dp, delimiter=";", index_col=False, skiprows=(1, 2), decimal="," , na_values=['no info', '.']) for dp in dps]
#extract time from all files
times = [df[['Time']] for df in dfs]
#list with channel names from each file
ch = [('Channel A'), ('Channel B'), ('Channel C'), ('Channel D')]
threshold_abs = 0.05
#loop to find the threshold crossing
booleans = []
for df in dfs:
for channel in ch:
for len1 in df[channel]:
if len1 > threshold_abs:
booleans.append(True)
else:
booleans.append(False)
is_long = pd.Series(booleans)
t = times[0][is_long].take([0])
print(t)
我不明白的是:
- 为什么“is_long 系列”只用一个元素创建,它有 24 组真/假列而不是 24 个单独的元素?因为我无法提取系列的各个元素来找到第一个实例越过阈值的相应时间。
我也怀疑缩进可能是错误的,因为我对所有 6 个文件都获得了相同的时间值。有人可以为我澄清一下吗?