I try to assign a value to column depending on value from another column:
This is the code i use:
Position = pd.Series([])
for i in range(len(df_empty)):
if df_empty["Rank"][i] > 2:
Position[i] = int(1)
else:
Position[i] = int(0)
df_empty.insert(4, "Position", Position)
| Return 3M | Rank | Position |
|---|---|---|
| 0.001036 | 3 | NAN |
| -0.031008 | 2 | NAN |
| -0.284040 | 1 | NAN |
I want the result to be:
| Return 3M | Rank | Position |
|---|---|---|
| 0.001036 | 3 | 1 |
| -0.031008 | 2 | 0 |
| -0.284040 | 1 | 0 |
What seems to be wrong with my code?
