I have a pandas dataframe of shape (75,9)
.
Only one of those columns is of numpy arrays, each of which is of shape (100, 4, 3)
I have a strange phenomenon:
data = self.df[self.column_name].values[0]
is of shape (100,4,3)
, but
data = self.df[self.column_name].values
is of shape (75,), with min
and max
are 'not a numeric object'
I expected data = self.df[self.column_name].values
to be of shape (75, 100, 4, 3), with some min
and max
.
How can I make a column of numpy arrays behave like a numpy array of a higher dimension (with length=number of rows in the dataframe)?
Reproducing:
some_df = pd.DataFrame(columns=['A'])
for i in range(10):
some_df.loc[i] = [np.random.rand(4, 6)]
print some_df['A'].values.shape
print some_df['A'].values[0].shape
prints (10L,)
,(4L,6L)
instead of desired (10L, 4L, 6L)
,(4L,6L)
np.stack(....values)
may create an array with the desired shape. It doesn't change the dataframe's own storage.