conditional according to previous panda column

0

I have a Panda DataFrame, and I want that according to the value of the previous column to execute a condition.

that is, if the value of column A is equal to 1, execute enter conditional i if it is 0 not enter the conditional.

A B C

1 1 0

0 0 0

instead of:

A B C

1 0 1

0 1 0

import pandas as pd
import numpy as np
array = np.ones(4)
df = pd.DataFrame(array)
for col in range(1,4):
 for index,row in df.iterrows():
    if df.loc[index,col-1] ==1
      rnd = np.random.randint(2, size=1)
      rnd= rnd[0]
      df.loc[index,col]=float(rnd)
    else:
      df.loc[index,col]=float(0)
    index=+1
col=+1
    
asked by francesc 13.03.2018 в 23:58
source

0 answers