I have a dataframe with multiple columns. I need to flag 4th value to 8th value in Column2 indicating these consecutive rows have values equal to 0.1
ID Column2 Column3
1 2.6 9
2 1.9 7
3 4.7 5
4 0.1 8
5 0.1 6
6 0.1 2
7 0.1 8
8 0.1 7
9 3.0 4
10 1.2 9
11 2.8 7
12 3.1 9
13 1.0 3
14 2.4 4
15 3.2 5
n nth value nth value
I used following code and it gave me TypeError. Can anyone please help?
Code:
import pandas as pd
df = pd.read_csv('file.csv')
for row, index in df_May.iterrows():
if row['Column2'] == row['Column2'].shift(1) | row['Column2'] == 0.1:
print index,row
TypeError: 'int' object has no attribute '__getitem__'