1

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 2

2

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']
Sign up to request clarification or add additional context in comments.

Comments

2

Use Series.str.get:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.