-1

I have a DF with a column that is a dictionary:

import pandas as pd

data = [10,{'self': 'https://elia.atlassian.net/rest/api/3/customFieldOption/10200', 'value': 'IT-Sourced Changes 2022', 'id': '10200'},30]
df = pd.DataFrame(data, columns=['Data'])

How do I create a new column that selects only one value e.g. 'IT-Sourced Changes 2022'?

Thank you!

  • 1
    `df['new_col'] = df['requirement_source'].str['value']` – mozway Sep 15 '22 at 06:49
  • 4
    Please, post [mre]. Also check [How to make good reproducible pandas examples](https://stackoverflow.com/q/20109391/4046632). Don't post images of code, error, data, etc. – buran Sep 15 '22 at 06:57

1 Answers1

0

df['new_col']= df['requirement_source'].str['value']

Should get the job done

Hassan Jalil
  • 1,114
  • 4
  • 14
  • 34
  • It works on my 'created' example but on my real data it gives me an error: 'ValueError: cannot reindex from a duplicate axis' – elia_Werner Sep 15 '22 at 12:40
  • are you concatenating multiple dataframes in your real data ? Basically you have duplicate index in your dataframe which gives this result. – Hassan Jalil Sep 16 '22 at 06:14