-1
for i in range(1, len(data)):
    currentItem = data[i]
  
    df.loc[i] = [data[i]['details']]
df
# Till here its working as I can extract the data.

But I need to extract number value only from details

When I use below code:

df = pd.DataFrame(data['details'])
number_list = df['number'].tolist() #list with numbers

It shows an error:

TypeError                                 Traceback (most recent call last)
<ipython-input-126-81553db4d7eb> in <module>
      4 df
      5 
----> 6 df = pd.DataFrame(data['details'])
      7 number_list = df['number'].tolist() #list with numbers

TypeError: list indices must be integers or slices, not str

This is how my data looks like

enter image description here

James Z
  • 12,209
  • 10
  • 24
  • 44
Mani
  • 1
  • 1
  • This [answer](https://stackoverflow.com/a/63311361/7758804) of the duplicate explains how to deal with your data, which is a column of strings, that must be converted to dicts, before being normalized. Please do not post the same question again. – Trenton McKinney Feb 14 '21 at 21:51

1 Answers1

-1

You can do it by calling apply on number series. Code below will create a new column.

df['extracted_number'] = df.details.apply(lambda x: x['number'])

You can also do it with regular python loop comprehension

number_list = [x['number'] for x in df.details]
Robert Axe
  • 396
  • 2
  • 11