Issue
I have a pandas data frame 'df', it looks like below but original data has many rows.
I would like to save this as .mat file with a name 'meta.mat'. I tried;
import scipy.io as sio
sio.savemat(os.path.join(destination_folder_path,'meta.mat'), df)
This creates the meta.mat file but it only writes the field names, when I open it in matlab it looks like this;
How can I fix this, thanks.
Solution
I don't think you can pass a pd.DataFrame
directly when scipy.io.savemat
is expecting a dict of numpy
arrays. Try replacing df
with the following in your call to savemat:
{name: col.values for name, col in df.items()}
Answered By - Kyle
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.