I have the following code
import numpy as np
import pandas as pd
test_array = np.array([(1, 2, 3), (4, 5, 6)],
dtype={'names': ('a', 'b', 'c'), 'formats': ('f8', 'f8', 'f8')})
test_df = pd.DataFrame.from_records(test_array)
test_df.to_records().view(np.float64).reshape(test_array.shape + (-1, ))
I expect a view on the original test_array to be returned, with shape (2, 3), however, I get this (2, 4) array.
rec.array([[0.e+000, 1.e+000, 2.e+000, 3.e+000],
[5.e-324, 4.e+000, 5.e+000, 6.e+000]],
dtype=float64)
Where did the extra column, column 0, come from?
Edit: I've just learned I can use DataFrame.values() to do the same thing, but I remain curious why this behavior exists.