I am having some trouble with the DataFrame and while loop:
A B
5 10
5 10
10 5
I am trying to have a while loop that:
while (Column A < Column B):Column A = Column A + (Column B / 2)Column B = Column B / 2
Any ideas how to do this.
I am having some trouble with the DataFrame and while loop:
A B
5 10
5 10
10 5
I am trying to have a while loop that:
while (Column A < Column B):Column A = Column A + (Column B / 2)Column B = Column B / 2
Any ideas how to do this.
You can vectorise this calculation to avoid explicit loops:
mask = df['A'] < df['B']df.loc[mask, 'A'] = df['A'] + df['B'] / 2
df.loc[mask, 'B'] = df['B'] / 2print(df)# A B
# 0 10.0 5.0
# 1 10.0 5.0
# 2 10.0 5.0