简体   繁体   中英

How To Create a Loop With Pandas and PyAutoGui.Write

I am using pyautogui to create a simple bot. However, in that bot, there is a point where I need to input information from a csv file individually and click "go". I have figured out how to do this indivudally with each row/column.

This is basically what I am using:

def function1():

    df = pd.read_csv('dbc.csv', header=None)
    doThisFirst()
    pyautogui.write(df.iloc[1, 0])
    thenDoThis()
    pyautogui.write(df.iloc[1, 1])
    ClickStuff()
    pyautogui.press('enter')
    sleep(for a bit of time)


Then the same for the next row.

Let's say there are 100 rows, I definitely do not want to write out up to function 100.

I have searched around and although I can find "some things" similar, I can't figure out how to write (df.iloc[nextrow, 0/1]) until the rows no longer have data.

I have thought of while true, or for i in df, and was able to get a "loop" working, but because it keeps writing the same row/columns, I haven't been able to test if it stops when there are no more rows.

Any help would be highly appreciated.

I think you can do it by just adding a for loop in the beginning:

def function1():
    for i in range(1, len(df)): # This will get executed for every row
        df = pd.read_csv('dbc.csv', header=None)
        doThisFirst()
        pyautogui.write(df.iloc[i, 0])
        thenDoThis()
        pyautogui.write(df.iloc[i, 1])
        ClickStuff()
        pyautogui.press('enter')
        sleep(for a bit of time)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM