我有一个csv格式如下
Time Marker
0 2104 21
1 2109 20
2 2485 21
3 2491 20
4 2867 22
5 2997 2
6 3248 23
我想计算21,22和23秒的发病率,在标记==20之间。唯一有效的标记在20个代码之间,所以前21个是无效的。多个有效的标记可以出现在一对20之间,所以我需要一个计数21,22和23之间发生一对20
因此,在上面的示例中,只有索引2可以是有效代码,因为它在两个20之间
我有一个满足Marker==20条件的索引列表
Indexrange = df.index[df['Marker'] == 20].tolist()
[1,
3,
10,
19,
22,
25,
29,
32,]
我如何循环浏览索引列表,并计算每对20岁儿童中21、22、23岁儿童的发病率?你知道吗
到目前为止,我已经:
TwentyOnes=0
TwentyTwos=0
TwentyThrees=0
for i in Indexrange:
for index, row in df.iterrows():
if index.between(i, i+1):
if Marker == 21
Count_of_21s +=
if Marker == 22
Count_of_22s +=
if Marker == 23
Count_of_23s +=
else:
InvalidCount+=
但我现在
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-16-4a72c2a77924> in <module>()
5 for i in Indexrange:
6 for index, row in df.iterrows():
----> 7 if index.between(i,i+1):
8 print(index, row['Marker'])
AttributeError: 'int' object has no attribute 'between'
如何仅获取IndexRange中索引之间的20对之间的值?你知道吗
所需输出为:Counts\u of \u 21s=int、Counts\u of \u 22s=int、Counts\u of \u 23s=int、InvalidCount=int
这是我的解决方案:
温的好多了。你知道吗
看来你需要
更新
相关问题 更多 >
编程相关推荐