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 make code more efficient (create a loop or function) for str.get() from column using pandas

I have a data frame with the nested fields. I need to extract only the display_value from the columns:
enter image description here

How to make my code efficient?

df['author'] = df['author'].str.get('display_value')
df['assigned'] = df['assigned'].str.get('display_value')
df['closed'] = df['closed'].str.get('display_value')
df['service'] = df['service'].str.get('display_value')

Thanks

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

>Solution :

This is cleaner and more efficient:

for column in df.columns:
    df[column] = df[column].str.get('display_value')
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