I have a pandas DataFrame in which one of the columns is made of tuples of floats. When I use arr = df['col_name'].to_numpy(), I end up with a 1D array of tuples, but I need a 2D array of floats.
My solution so far is to use arr = np.array(df['col_name'].to_list()). This works, but it seems inefficient to convert first to a list and then to an array. So I'm wondering, is there a better way to do this?
This question is related, but the only answer there points to reading a text file differently, which is not an option for me since the data is already in the DataFrame.
toliststep is probably fast. An alternative might bevstackdf['col_name'].dtypeandarr.dtypereturn dtype('O'). So I should stick to the current approach?to_listshould be pretty fast.