How to modify a column of a pandas dataframe?

One column of my dataframe its in the following format:

{'name': 'Aimo'}
{'name': 'Aimo'}
{'name': 'Aimo'}
{'name': 'Aimo'}
{'name': 'Aimo'}

The dtype of the column is object. How can I modify this column in the following format?

Aimo
Aimo
Aimo
Aimo
Aimo

Probably the new dtype would be character. Thank you in advance!

2 answers

  • answered 2021-09-23 12:24 U12-Forward

    I guess if they're dictionaries, do:

    df['column'] = df['column'].str['name']
    

    Or parse them as dictionaries if they are not already:

    from ast import literal_eval
    df['column'] = df['column'].map(literal_eval).str['name']
    

  • answered 2021-09-23 12:25 jezrael

    Use Series.str.get:

    df['column'] = df['column'].str.get('name')
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum