I have a dataframe of about 10,000 rows. Each record includes a Recordid and an integer that represents the number of days since the start for that RecordID. For example:
df = pd.DataFrame( {
"RecordID" : ["id1", "id2", "id3", "id4", "id5" , "id1", "id2", "id3", "id4", "id5" ] ,
"number_of_days" : [1,1,1,1,1,2,2,2,2,2]})
df
RecordID number_of_days
0 id1 1
1 id2 1
2 id3 1
3 id4 1
4 id5 1
5 id1 2
6 id2 2
7 id3 2
8 id4 2
9 id5 2
I'd like to add a column that contains a random number between 1 and 100. But I need the random to be higher than the previous random value for each ID. This is an example of what I would like to get:
RecordID number_of_days random_value
0 id1 1 10
1 id1 2 13
2 id1 3 45
3 id1 4 50
4 id1 5 62
5 id1 6 80
6 id1 7 81
7 id1 8 82
8 id1 9 92
9 id1 10 99
10 id2 2 12
11 id2 4 31
I see posts about creating a field with random values. I'm not finding any that address the need for generating random values that increase, though.
Aucun commentaire:
Enregistrer un commentaire