-3

I would like to create a dummy variable for % Change PMI. If % Change PMI is positive is 1 and if negative a 0.

print(Overview3)

            Adjusted Close  % Change PMI  % Change IP
Date                                                 
1970-02-27        0.052693     -0.026694      -0.0007
1970-03-31        0.001453     -0.010549      -0.0013
1970-04-30       -0.090483     -0.040512      -0.0026
1970-05-29       -0.060967      0.048889      -0.0012
1970-06-30       -0.050033      0.082627      -0.0032
...                    ...           ...          ...
2020-08-31        0.070065      0.035382       0.0096
2020-09-30       -0.039228      0.001799      -0.0008
2020-10-30       -0.027666      0.055655       0.0101
2020-11-30        0.107546     -0.018707       0.0089
2020-12-31        0.037121      0.048527       0.0102

[611 rows x 3 columns]
bad_coder
  • 11,289
  • 20
  • 44
  • 72
  • 1
    Please see: [Why is “Does anyone can help?” not an actual question?](http://meta.stackoverflow.com/q/284236) – Mike Scotty Apr 20 '21 at 15:19
  • 1
    Also, this is very, *very* basic. You should know how to solve this question after reading one or two short `pandas` tutorials. – timgeb Apr 20 '21 at 15:21
  • 1
    Does this answer your question? [Creating dummy variables in pandas for python](https://stackoverflow.com/questions/11587782/creating-dummy-variables-in-pandas-for-python) – semblable Apr 20 '21 at 23:48

1 Answers1

-1
df['dummy'] = 0
for i in range(0,len(df)):
    if df["% Change PMI"][i] > 0:
        df['dummy'][i] = 1
    else:
        df['dummy'][i] = 0
domiziano
  • 440
  • 3
  • 13