mercredi 26 avril 2017

Select the random row from dataframe and insert into another dataframe

I have two table 1.reason with 9 records and another one is id dataframe with 40k records.

ID

+------+------+
|pc_pid|pc_aid|
+------+------+
|  4569|  1101|
| 63961|  1101|
|140677|  4364|
|127113|     7|
| 96097|   480|
|  8309|  3129|
| 45218|    89|
|147036|  3289|
| 88493|  3669|
| 29973|  3129|
|127444|  3129|
| 36095|    89|
|131001|  1634|
|104731|   781|
| 79219|   244

reasons

+-----------------+
|          reasons|
+-----------------+
|        follow up|
|         skin chk|
|      annual meet|
|review lab result|
|        REF BY DR|
|       sick visit|
|        body pain|
|             test|
|            other|
+-----------------+

I want output like this

|pc_pid|pc_aid| reason 
+------+------+-------------------
|  4569|  1101| body pain
| 63961|  1101| review lab result
|140677|  4364| body pain
|127113|     7| sick visit
| 96097|   480| test
|  8309|  3129| other
| 45218|    89| follow up
|147036|  3289| annual meet
| 88493|  3669| review lab result
| 29973|  3129| REF BY DR
|127444|  3129| skin chk
| 36095|    89|  other

In the reasons I have only 9 records and in the ID dataframe I have 40k records, I want to assign reason randomly to each and every id.




Aucun commentaire:

Enregistrer un commentaire