'how to make array from arrays in python

I want to make np.array from many arrays inside the array, so my object shape should be (n, 43,49).

I am trying to do this now:

b = data[data['column'] == list_of_column_names[0]].values

for i in range (1,4):
list_of_ekch[i] = (data[data['column'] == list_of_column_names[i]].values)
b = np.array((list_of_ekch[i] ,  b))

So in my result I am geting such shape: (2,)

But my goal from this example to get shape : (4,)

Maybe someone could help for me?

I tried to get array from matrices.



Solution 1:[1]

if your input data is a dataframe of size (9000*43 x 49) where 9000 is the number of firm, 43 is number of row per firm, and 49 is number of columns of your input data, then you can first sort your dataframe by the name of the firms, then reshape.

data.sort_values('firm_name').values.reshape((-1, 43, 49))

-1 allows you to not specify the number of firms. If it is exactly 9000, then you can replace -1 with 9000.

Note that for this to work, each firm has to have the same number of rows, which seems to be the case based on your description of the question.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Raymond Kwok