I have converted a mat file into python dictionary. Now how can i convert this into Pndas data frame.
CodePudding user response:
IIUC use if need create dictionary of DataFrames
:
d = {k: pd.DataFrame(v) for k, v in matdata.items()}
CodePudding user response:
Assuming you want to flatten the arrays:
df = pd.DataFrame({k: v[0] for k,v in matdata.items()})
example:
matdata = {'a': np.array([[1,2,3], [4,5,6]]), 'b': np.array([[7,8,9],[10,11,12]])}
df = pd.DataFrame({k: v.ravel() for k,v in matdata.items()})
output:
a b
0 1 7
1 2 8
2 3 9
3 4 10
4 5 11
5 6 12