Home > Enterprise >  Extracting data from dictionary in panda data-frame
Extracting data from dictionary in panda data-frame

Time:11-10

I am working on cleaning data I scrapped and one of the columns is in for of dictionary in a list. How can I extract the values of the list in new column. The column name is "age " as shown in the screenshot.

Best regards

I have tried using pandas extract function but did not work.

df['age_claen'] = dff['age'].str.fullmatch('age_message')

screenshot from jupyter notebook

CodePudding user response:

 df['age_clean'] = [list(e[0].values()) for e in df['age']]

The [0] is due to that looks like each value is a dict inside a one-value-list.

Try it.

Regards,

CodePudding user response:

Try this:

df = df.join(df.pop('age').apply(lambda x: pd.Series(x[0]))).rename(columns={'age_message' : 'age_clean'})
  • Related