I'm trying to create duplicate rows during a dataframe iteration. Basically, I have two for loops wherein in the first loop, I'm feeding values into an API, and in the second loop, I'm extracting values from the JSON output.
I want to duplicate the current row and create N rows based on how many items are on the list. For example:
Name Date Sales
John 1/1/17 100
Bob 1/2/17 200
items = []
for row in df.sales:
url = 'www.samplewebsite.com/values=xyz/APIKEY=MYAPIKEY'
result = simplejson.load(urllib.urlopen(url))
for i in range(0, len(result['column a'][0]['column b']:
items.append(result['column a'][0]['column b'][i]['item'])
In this particular loop, two lists are created (one for John, the other for Bob):
items = ['Paper','Paper Clips','Pencils']
items = ['Notebook','Stapler','Highlighter','Pen']
Desired output:
Name Date Sales Item
John 1/1/17 100 Paper
John 1/1/17 100 Paper Clips
John 1/1/17 100 Pencils
Bob 1/2/17 200 Notebook
Bob 1/2/17 200 Stapler
Bob 1/2/17 200 Highlighter
Bob 1/2/17 200 Pen
Thank you in advance!