I have a pandas data frame with 2 columns(UserId,RandNo). In this UserId has the values for 10 rows as below
Now, I fill the RandNo column through for loop as below.
import pandas as pd
import random
df=pd.read_csv('df_sto.csv', skipinitialspace=True)
rand=0
for index, row in df.iterrows():
try:
rand=random.randint(0,100)
df.at[index, 'RandNo'] = rand
except Exception as e:
print(e)
df.to_csv("df_sto1.csv", sep=',')
Here, I get the updated value in df_sto1.csv file only, the updated value not affected in df_sto.csv.
If the data frame rows are large and if the for loop face any problem after 95% of rows are updated in df.iterrows(): for 'df_sto.csv' Then I want to repeat the process form 0% itself(from 0th row itself). To avoid this problem I want to update the data frame for 'df_sto.csv' each and every for loop iteration itself rather than to get updated value through df.to_csv("df_sto1.csv", sep=',')
Guide me to update the data frame cell value using for loop in each iteration itself. Thanks in advance.

RandNocolumn at once?