I tried to get the index of node_id column with specific value but my code doesn't return anything but return the index of option column. I can not tell the reason why there is the diffs between two columns. Could any one give me tips ?? Thank you so much.
client_data = """node_id,option,before_id
1,A,
5,A,4
3,B,2
4,C,1
8,C,2
6,A,
2,A,1
7,C,6
"""
df = pd.read_csv(io.StringIO(client_data), dtype='string', error_bad_lines=False)
before_ind = df.loc[df['node_id'] == 1].index
print(before_ind)
output of before_ind = df.loc[df['node_id'] == 1].index
Int64Index([], dtype='int64')
If I do before_ind = df.loc[df['option'] == 'C'].index
node_id option before_id
3 4 C 1
4 8 C 2
7 7 C 6