I put this dataframe as an example:
import pandas as pd df = pd.DataFrame({'country':['china','canda','usa' ], 'value':[1000, 850, 1100], 'fact':[1000,200,850]}) df.index=df['country'] df = df.drop('country', axis=1) I want to iterate over the GDP of each country and into this iteration I want to create a new column that would be full of 1 or 0 in function of a condition:
for x in df['value']: if x > 900: df['answer']=1 else: df['answer']=0 I would expected a column with the following values:
[1,0,1] Because Canada has a value lower than 900.
But instead I have a column full of ones.
What is wrong?