I have the following dataframe (in fact, part of a much larger dataframe, where the Keyβs repeat arbitrarily, sometimes even more than twice):
df_ini = DataFrame(
Key = [170, 447, 447, 699, 963, 963, 963, 756],
Type = ["No", "No", "No", "Yes", "Yes", "Yes", "Yes", "No"],
Situation = ["Closed", "Pending", "Surpassed", "Surpassed", "Pending", "Surpassed", "Faulty", "Surpassed"]
)
I would like to manipulate df_ini
so as to obtain the transformed dataframe:
df_fin = DataFrame(
Key = [170, 447, 699, 963, 756],
Type = ["No", "No", "Yes", "Yes", "No"],
Situation = ["Closed", "Pending, Surpassed", "Surpassed", "Pending, Surpassed, Faulty", "Surpassed"]
)
That is, the rows where the column Key
are equal and have the corresponding column Situation
different must be rendered into a single row, such that all the corresponding columns are the same, except for the column Situation
, which must have a join of the String values in the original cells of the βunmergedβ rows (separated by commas).
Thanks in advance.