0

I have a list of 5 matrices:

import numpy as np
import pandas as pd
a=[(np.random.randint(2,size=(2,3))) for i in xrange(5)]

How do I create a pandas DataFrame of 5 records with a single column containing a matrrix for each row?

1 Answer 1

2

You can create the dataframe by running :

df= pd.DataFrame({'array':a})

Output :

   array
0  [[0, 0, 0], [0, 0, 0]]
1  [[0, 1, 1], [0, 0, 0]]
2  [[1, 0, 0], [0, 1, 1]]
3  [[1, 0, 1], [1, 0, 0]]
4  [[0, 0, 0], [0, 0, 1]]

If you want to apply cumsum over the column you can use apply

df['array']=df['array'].apply(np.cumsum)

output:

                array
0  [0, 0, 0, 0, 0, 0]
1  [0, 1, 2, 2, 2, 2]
2  [1, 1, 1, 1, 2, 3]
3  [1, 1, 2, 3, 3, 3]
4  [0, 0, 0, 0, 0, 1]
Sign up to request clarification or add additional context in comments.

1 Comment

Updated my answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.