Python:在while循环中结合for循环,迭代数据中的行
Python: Combine for loop in while loop and iterate rows in a data
我想迭代数据行并在达到条件后打印最后一行。我的代码看起来像这样
D_sum = 4.39e-05
count = 0
while D_sum < 1:
for row in df.iterrows():
count += 1
D_sum += D_sum
print('count', count)
print('D_sum', D_sum)
print('row', row)
break # When i write break the loop is executing correct but, its not printing final row. Its printing first row of data.
如果我不写 Break,循环将继续并在某些迭代后结束。
我试着写了这段代码
count = 0
flag = True
while flag:
for row in df.iterrows():
count += 1
D_sum += (df[['Di']].sum()).values
print('count:', count)
print('D_sum', D_sum)
print(row)
if D_sum == 1:
flag = False
但这也会持续到某些迭代(无限循环)
请帮我更正python
中的代码
D_sum = 4.39e-05
count = 0
for row in df.iterrows():
count += 1
D_sum += D_sum
print('count', count)
print('D_sum', D_sum)
# Check your condition here
if D_sum >= 1:
print('row', row)
break
我想迭代数据行并在达到条件后打印最后一行。我的代码看起来像这样
D_sum = 4.39e-05
count = 0
while D_sum < 1:
for row in df.iterrows():
count += 1
D_sum += D_sum
print('count', count)
print('D_sum', D_sum)
print('row', row)
break # When i write break the loop is executing correct but, its not printing final row. Its printing first row of data.
如果我不写 Break,循环将继续并在某些迭代后结束。
我试着写了这段代码
count = 0
flag = True
while flag:
for row in df.iterrows():
count += 1
D_sum += (df[['Di']].sum()).values
print('count:', count)
print('D_sum', D_sum)
print(row)
if D_sum == 1:
flag = False
但这也会持续到某些迭代(无限循环) 请帮我更正python
中的代码D_sum = 4.39e-05
count = 0
for row in df.iterrows():
count += 1
D_sum += D_sum
print('count', count)
print('D_sum', D_sum)
# Check your condition here
if D_sum >= 1:
print('row', row)
break