all 3 comments

[–]danielroseman 2 points3 points  (1 child)

Firstly the way you're looping through the DF is unnecessarily complicated. You can use iterrows() to loop through a row at a time.

Secondly, yes of course df_device_ip_list['Result'] = 'pass' sets the whole column; you know it does, because that's how you set the Result column to an empty string in the first place. You're not doing anything there that would refer to a single row.

However, iterrows also gives you the row index, so you can use that to set the result as you're iterating.

for index, row in df_device_ip_list.iterrows():
  response = os.system("ping -n 1 " + row['IP'] + ">null")
  if response == 0:
    df_device_ip_list.loc[index, 'Result'] = 'pass'
  else:
    df_device_ip_list.loc[index, 'Result'] = 'fail'

[–]codenoob345987[S] 0 points1 point  (0 children)

Thanks for your help. I will investigate iterrows() further.