0

I would like to extract the text inside the range "text: ....." from this dataframe and create another column with that value.

This is my Pandas Dataframe

enter image description here

issues_df['new_column'] = issues_df['fields.description.content'].apply(lambda x: x['text'])

However, it returns the following error:

issues_df['new_column'] = issues_df['fields.description.content'].apply(lambda x: x['text'])
TypeError: Object 'float' is not writable.

Any suggestions?

Thanks in advance.

Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52
Junior P
  • 41
  • 9
  • 1
    Please [do not upload images of code/data/errors when asking a question](http://meta.stackoverflow.com/q/285551) and provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example), including a small example input data and the corresponding expected result. – Pierre D Aug 09 '22 at 15:05
  • 2
    the column values are list not object try to change `x["text"]` to `x[0]["content"][0]["text"]` – Mouad Slimane Aug 09 '22 at 15:08
  • perhaps this helps https://stackoverflow.com/questions/51660357/extract-substring-between-two-characters-in-pandas/51660658#51660658 – Yuca Aug 09 '22 at 15:12

2 Answers2

2

Problem is NaN in column, you can try .str accessor

issues_df['new_column'] = issues_df['fields.description.content'].str[0].str['content'].str[0].str['text']
Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52
0

That could be a good task for the rather efficient json_normalize:

df['new_column'] = pd.json_normalize(
    df['fields.description.content'], 'content'
)['text']
Pierre D
  • 24,012
  • 7
  • 60
  • 96