I need to extract/clean the contents of a df (series), keeping only the first record (on the left) for each element between the parentheses.
I will put the current tables and how I need the information, as it makes it easier to observe the problem.
Current df:
| ID | chords |
|---|---|
| 1 | [(N, 0.371519274), (A7, 0.464399092)] |
| 2 | [(N, 0.371519274), (Em, 0.464399092)] |
Desired df:
| ID | chords |
|---|---|
| 1 | N, A7 |
| 2 | N, Em |
Is this desired df possible?
>Solution :
Assuming the values of chords column are lists of tuples
df['chords'] = df['chords'].map(lambda lst: ", ".join(tup[0] for tup in lst))