Home > Software design >  How to make code more efficient (create a loop or function) for str.get() from column using pandas
How to make code more efficient (create a loop or function) for str.get() from column using pandas

Time:05-10

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

CodePudding user response:

This is cleaner and more efficient:

for column in df.columns:
    df[column] = df[column].str.get('display_value')
  • Related