Skip to content
Advertisement

How to add row to dataframe that keeps tuple as a tuple rather than splitting out into two elements?

I have a dataframe that I’d like to iteratively add rows to. The columns are an integer for ‘time’, an (x,y) coordinates and a dichotomous status. For the sake of this example, rather than the full iteration, I will just demonstrate the issue with adding one row to the dataframe, rather than lots. The issue appears to be that when I concatenate the new row to the existing dataframe, it breaks apart my tuple (5,0) in to two integer values, and so there are two rows attempting to be added rather than just the one, and so I get the error: “ValueError: arrays must all be same length”. How can I fix this?

JavaScript

Advertisement

Answer

You just need to add brackets around coordinates[50] to avoid splitting your tuple:

JavaScript

(End of) output:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement