[英]How To Create a Loop With Pandas and PyAutoGui.Write
I am using pyautogui to create a simple bot.我正在使用 pyautogui 创建一个简单的机器人。 However, in that bot, there is a point where I need to input information from a csv file individually and click "go".
但是,在那个机器人中,有一点我需要从 csv 文件中单独输入信息,然后单击“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.假设有 100 行,我绝对不想写出最多 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.我四处搜索,虽然我可以找到类似的“一些东西”,但我无法弄清楚如何编写 (df.iloc[nextrow, 0/1]) 直到行不再有数据。
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.我已经想到了 while true,或者 for i in df,并且能够使“循环”工作,但是因为它一直在写入相同的行/列,所以我无法测试它是否在没有时停止更多行。
Any help would be highly appreciated.任何帮助将不胜感激。
I think you can do it by just adding a for loop in the beginning:我认为您可以通过在开头添加一个 for 循环来实现:
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.