I have an array of objects of this class
class CancerDataEntity(Model):
age = columns.Text(primary_key=True)
gender = columns.Text(primary_key=True)
I would like to emphasize Jim Hunziker's comment.
pandas.DataFrame([vars(s) for s in signals])
It is far easier to write, less error-prone and you don't have to change the to_dict()
function every time you add a new attribute.
If you want the freedom to choose which attributes to keep, the columns parameter could be used.
pandas.DataFrame([vars(s) for s in signals], columns=['x', 'y'])
The downside is that it won't work for complex attributes, though that should rarely be the case.