Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to Select the First Element of a Series (Python)

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading