Reputation: 7
I am trying to convert this python object to a pandas dataframe. But it's saying that it's not 1-Dimensional so it cannot convert. It was originally a .mat file that I converted to a python list. The list looks like this when printed:
{'__header__': b'MATLAB 5.0', '__version__': '1.0', '__globals__': [], 'val': array([[-20, -17, -2, ..., -11, -4, -11],
[-12, -8, -5, ..., -9, -9, -9]], dtype=int16)}
Upvotes: 0
Views: 25269
Reputation: 1310
Try this way:
if you want to 2 columns
pd.DataFrame(data['val'].T)
Output:
0 1
0 -20 -12
1 -17 -8
2 -2 -5
3 -11 -9
4 -4 -9
5 -11 -9
else you can do
pd.DataFrame(data['val'])
Output :
0 1 2 3 4 5
0 -20 -17 -2 -11 -4 -11
1 -12 -8 -5 -9 -9 -9
Upvotes: 2
Reputation: 41
I think you are looking for this function:
[https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.from_dict.html]
Upvotes: 0