0

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)}

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you @ShubhamShswat, this is what I was searching for.
@AdarshMishra depending on what you want to be part of your df, since if you just interested in arrays you can do this way
0

I think you are looking for this function:

[https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.from_dict.html]

2 Comments

Hi @salmanhammad this didnt work either. It's showing the same error. Exception: Data must be 1-dimensional
I see. it cant sort the 'val' array which is a mat in one column. you will have to reshape 'val' array first to a one dim or save it in a different dataframe.

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.