Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Appending new elements into an empty list

Im facing issue with appending new elements into list. In first SS the data is shown which means it is present but when Im appending the data in a loop, the data shown is Nan. Please refer to the screen shots.

Data showing (screenshot)

result_items[0]['Media'][0]['Description']

Result NaN (screenshot)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

for result in result_items:
    try:
            media_description.append(result[0]['Media'][0]['Description'])
    except:
            media_description.append(np.nan)   

media_description

>Solution :

In your 2nd image/cell of code, you are using result[0] whereas result itself is the element of the list, so there was no need to subscript the element.

Replacing the line in 2nd cell with the following will fix the issue

media_description.append(result['Media'][0]['Description']) 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading