I would like to change every second row of my data frame.
I have a df like this:
Node | Feature | Indicator | Value | Class | Direction
--------------------------------------------------------
1 | WPS | <= | 0.27 | 4 | 1 -> 2
--------------------------------------------------------
2 | ABC | <= | 0.40 | 5 | 1 -> 3
--------------------------------------------------------
3 | CXC | <= | 0.45 | 2 | 2 -> 4
--------------------------------------------------------
4 | DFT | <= | 0.56 | 1 | 2 -> 5
--------------------------------------------------------
5 | KPL | <= | 0.30 | 3 | 3 -> 5
--------------------------------------------------------
6 | ERT | <= | 0.55 | 5 | 3 -> 1
I would like the following:
Node | Feature | Indicator | Value | Class | Direction
--------------------------------------------------------
1 | WPS | <= | 0.27 | 4 | 1 -> 2
--------------------------------------------------------
2 | WPS | > | 0.27 | 5 | 1 -> 3
--------------------------------------------------------
3 | CXC | <= | 0.45 | 2 | 2 -> 4
--------------------------------------------------------
4 | CXC | > | 0.45 | 1 | 2 -> 5
--------------------------------------------------------
5 | KPL | <= | 0.30 | 3 | 3 -> 5
--------------------------------------------------------
6 | KPL | > | 0.30 | 5 | 3 -> 1
So every second row changes the 'Feature' and 'Value' into the same as the row above, and the 'Indicator' is changed to '>'
I can't figure out how to iterate through the Dataframe (using iterrows I suppose) and changing only every second row?
EDIT:
I have tried the following as recommended:
my_df = pd.DataFrame()my_df['N'] = [1, 2, 3, 4, 5, 6]my_df['I'] = ['=>', '=>', '=>', '=>', '=>', '=>']my_df['F'] = ['a', 'b', 'c', 'd', 'e', 'f']my_df.loc[1::2, 'F'] = Nonemy_df.loc[1::2, 'I'] = '>'my_df.fillna(method='ffill')print(my_df)
Output:
N I F
0 1 => a
1 2 > None
2 3 => c
3 4 > None
4 5 => e
5 6 > None