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?
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]