Python Pandas 迭代每一行执行命令并根据某些条件循环到下一行

问题描述 投票:0回答:1

嗨,我想在相应项目的列中运行运行脚本并进行设置,然后移动到下一行并执行相同的操作。
我有单独的 python 脚本来发送邮件到 MAIL_LIST

[数据框]https://i.sstatic.net/yqS8oX0w.png


for idx,sheet_1 in enumerate(sheet_list):
    print("sheet_name=",sheet_name)
    print("idx=",idx)

    df= pd.read_excel(excel_name, sheet_name=sheet_1)
    mail_list = core_auto['MAIL_LIST']
    project_name = core_auto['PROJECT_NAME']
    setting_name = core_auto['SETTING_NAME']
    project_source = core_auto['PROJECT_SOURCE']
    version_name = core_auto['VERSION_NAME']
    run_script = core_auto['RUN_SCRIPT']

     for i in range(len(core_auto.index)):
         for idx, row in core_auto.loc[i:i+1].iterrows():
           print(idx, row)

python pandas excel dataframe loops
1个回答
0
投票

看起来您想要迭代 DataFrame core_auto 中的行并根据每行中的值执行一些操作。假设每一行对应一个项目及其设置,并且您想为每个项目执行一个脚本,可以使用以下方法:

# For sending mail to MAIL_LIST, you can use your separate Python script

# After performing actions for the current project, move to the next row and repeat the process

此代码迭代 DataFrame core_auto 中的每一行,提取当前行中每一列的值,然后您可以使用这些值来执行所需的操作,例如执行脚本或发送电子邮件。当前行的操作完成后,循环将移至下一行并重复该过程。

© www.soinside.com 2019 - 2024. All rights reserved.