我的代码如下:
for index, row in df_csv_mk.iterrows():
exp1_high= df_metrics[df_metrics.time == row['time1_high']]['absolute exposure']
exp1_high = exp1_high.values
df_exposure_mkresult=df_exposure_mkresult.append({'exp1_high': exp1_high}, ignore_index=True)
和我得到的数据框:
exp1_high
0 []
1 []
2 [0.00666628]
3 [0.00674054]
4 [0.00661782]
5 [0.0066166]
6 [0.00660748]
7 [0.00645245]
8 [0.006456]
从我看到的是一列由数组组成的列,但是当我尝试提取一个数组的元素(exp1_high [0])时,我收到错误消息(索引0超出了轴0的大小为0的范围) ...有什么帮助吗?请不要将其重复,我已经在其他问题上尝试了其他解决方案...谢谢!
以下完整错误:
IndexError Traceback (most recent call last)
<ipython-input-757-47395f0c238c> in <module>
10 exp1_high= df_metrics[df_metrics.time == row['time1_high']]['absolute exposure']
11 exp1_high = exp1_high.values
---> 12 print(exp1_high[0])
13 df_exposure_mkresult=df_exposure_mkresult.append({'exp1_high': exp1_high}, ignore_index=True)
14
IndexError: index 0 is out of bounds for axis 0 with size 0
答案 0 :(得分:0)
for index, row in df_csv_mk.iterrows():
exp1_high= df_metrics[df_metrics.time == row['time1_high']]['absolute exposure']
exp1_high = exp1_high.values
if exp1_high.size == 0:
df_exposure_mkresult=df_exposure_mkresult.append({'exp1_high': 0}, ignore_index=True)
else:
df_exposure_mkresult=df_exposure_mkresult.append({'exp1_high': exp1_high[0]}, ignore_index=True)
前两行为空...