0
I have a Dataframe with numerous columns, but for the following question the important columns are:
- ID (number) of the report
- Product
- Event
Example:
id_relato | event | product |
---|---|---|
456 | edema | medication1 |
456 | itching | |
456 | sleepiness | |
789 | erythema | medication2 |
789 | dizziness |
A single product report may contain more than 1 Event and therefore may contain more than 1 line. However, the product is not filled in the other lines, only in the first one and so I made a for loop to insert the name of this product in these other lines of the Product column.
for i in relatos['id_elato']:
relatos.loc[relatos['id_elato'] == i, 'produto'] = list(relatos.loc[relatos['id_elato'] == i]['produto'].unique())[0]
Upshot:
id_relato | event | product |
---|---|---|
456 | edema | medication1 |
456 | itching | medication1 |
456 | sleepiness | medication1 |
789 | erythema | medication2 |
789 | dizziness | medication2 |
I get the expected result, however, in a larger dataframe the processing is very time consuming. So there would be better performing alternatives than for loop?