mercredi 6 juillet 2022

Adding multiple columns randomly to a dataframe from columns in another dataframe

I've looked everywhere but can't find a solution.

Let's say I have two tables:

Year
1
2
3
4

and

ID  Value
1    10
2    50
3    25
4    20
5    40

I need to pick randomly from both columns of the 2nd table to add to the first table - so if ID=3 is picked randomly as a column to add to the first table, I also add Value=25 i.e. end up with something like:

Year  ID  Value
1     3     25
2     1     10
3     1     10
4     5     40
5     2     50



Aucun commentaire:

Enregistrer un commentaire