How to iterate and modify rows in a dataframe( convert numerical to categorical)
As the error suggests, you don't have a column called Y1. Hence the error. Here is my suggestion to fix this. Assuming you input data looks like this - 

15.55
15.55
15.55
15.55
20.84


Read it in pandas this way - 

import pandas as pd

df = pd.read_csv('path/to/file.csv', header=None)


Provide a column name for this - 

df.columns = ['Y1']


If you have more columns, just fill the df.columns list accordingly.

Finally, use the pandas best practices as per their latest documentation to assign a new column - 

df = df.assign(Y2= (df['Y1'] &gt; 18.250000).astype(int))


Output

print(df)

 Y1  Y2
0  15.55   0
1  15.55   0
2  15.55   0
3  15.55   0
4  20.84   1


Note: Since I don't have full visibility on what you are working on, I have assumed what might be the problems you are facing. If this doesn't work let me know.