0

How can I do a where clause for C3? I want to do in the scenario below:

df1 = pd.read_excel(path)
for index, row in df1.iterrows():
    C1 = row[2]
    C2 = row[7]
    C3 = if (row[12]) == 0 then 'blue' else 'green'
    List.append([C1, C2, C_3])

C3 = if (row[12]) == 0 then 'blue' else 'green' it is not working. I need something similar

cufta05
  • 13
  • 3

1 Answers1

0

Try to avoid loops with pandas. ex.

df1 = pd.read_excel(path)
C1 = df1.iloc[:, 2]     # [rows, columns]
C2 = df1.iloc[:, 7]  
C3 = numpy.where(df1.iloc[:, 12]==0, 'blue', 'green')
List = pd.concat([C1, C2, C3], axis=1)
finman69
  • 309
  • 1
  • 8