That is really weird. Try to print element. Is it possible that data has different types of elements,e.g. data[0] is dict, but are all elements dict?
print(set(type(element) for element in data))
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs