Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)
edited by

I have a form set in Django which has multiple forms which I am saving as:

manifestData = form.cleaned_data

If I print(manifest data) it returns the below:

[{'ProductCode': <Product: APPLES-1>, 'UnitQty': u'11', 'Price': u'11.00', 'Amount': u'121', 'DescriptionOfGoods': u'Washington Extra Fancy', 'Type': u'Cases', u'id': None, u'DELETE': False}, {'ProductCode': <Product: ORANGES-1>, 'UnitQty': u'1', 'Price': u'12.00', 'Amount': u'12', 'DescriptionOfGoods': u'SUNKIST ORANGES', 'Type': u'Cases', u'id': None, u'DELETE': False}]

I need to access each Product Code and pop it from the list. So I am trying the below in my view:

...

for item in manifestData:

   x = manifestData.pop['ProductCode'] #this is highlighted in the error message

...

When I do this I get a TypeError reading that "an integer is required". Can anyone explain that to me / how I can navigate this issue?

1 Answer

0 votes
by (36.8k points)
edited by

In the code, manifestData is a list of dictionary. In your for loop, you are looping through the list to get each dictionary, but then you try to pop from manifestData, rather than an item.

Change your code to be:

...

for item in manifestData:

   x = item.pop('ProductCode') #pop from item, not manifestData

...

If you want to know more about the Data Science then do check out the following Data Science which will help you in understanding Data Science from scratch 

Browse Categories

...