I have a dataframe-
DATE CITY_NAME WEEK_NUM
0 2019-12-01 Bangalore 48
1 2019-12-01 Delhi 48
2 2019-12-02 Bangalore 49
3 2019-12-02 Delhi 49
Now I want to add a new column to the dataframe and add a row to the new column in a loop. I did this-
R1['Hi']=0
for a,b in zip(R1['DATE'],R1['CITY_NAME']):
R1['Hi'].loc[-1]=random.randrange(10)
I am using a default value 5 here but I am but its showing-
DATE CITY_NAME WEEK_NUM Hi
0 2019-12-01 Bangalore 48 0
1 2019-12-01 Delhi 48 0
2 2019-12-02 Bangalore 49 0
3 2019-12-02 Delhi 49 0
lets assume the f output of rand is [2,3,1,6]
then final output will be-
DATE CITY_NAME WEEK_NUM Hi
0 2019-12-01 Bangalore 48 2
1 2019-12-01 Delhi 48 3
2 2019-12-02 Bangalore 49 1
3 2019-12-02 Delhi 49 6