0

While loop doesn't send all line parameters before stopping thus finishes after second pass and sometimes directly after first pass.

i have tried reducing the number of steps but plays little difference

import requests
import rek #request script
import time
import pandas as pd
dfbig= pd.read_csv ('C:\\Users\\libraries2.csv')



step = 19
init = 0; final = init + step
while (final<= dfbig.shape[0]):
    df = dfbig.iloc [ init : final ]
    rek.req (df , init, final) 
    init = final
    final = init + step
    time.sleep (60)

It just stops before completing all lines of csv

Devesh Kumar Singh
  • 20,259
  • 5
  • 21
  • 40
George
  • 1

1 Answers1

0

Your code is incrementing final at the end of the loop. On the 2nd iteration final exceeded dfbig.shape[0] (ie: 19+19+19 <= 43 is false) thereby ending the loop. This has the effect of skipping over the last 5 rows.

To resolve:

step = 19
init = 0
final = init + step
while (init <= dfbig.shape[0]):
    df = dfbig.iloc[init:final]
    rek.req (df , init, final) 
    init = final
    final = init + step

Building on this chunking idea you could do this to simplify:

rows = dfbig.shape[0]
for i in range(0, rows, step):
    df = dfbig.iloc[i:i + step]
    rek.req(df, i, i + step) 
Richard
  • 2,994
  • 1
  • 19
  • 31