I'm trying to use a for loop to iterate over an array and add items (new rows) to the dataframe. But when I I print out the DataFrame it's empty. I must be doing something wrong.
Here's my code:
sdf = pd.DataFrame(columns=('Question', 'Answer', 'Total', 'Percent'))
for i, data in enumerate(q_array):
sdf.append({'Question': data.get_question(), 'Total': data.get_total()}, ignore_index=True)
for answer, number in data.get_answers().items():
sdf.append({'Answer': answer, 'Total': number, 'Percent': number_to_percent(number, data.get_total())}, ignore_index=True)
sdf.to_excel(writer, 'stats', index=False)
print(sdf)
Any suggestions on simply adding a new row, then adding data to the appropriate column?
pd.concat