Skip to content

Instantly share code, notes, and snippets.

@BexTuychiev
Last active July 14, 2020 09:07
Show Gist options
  • Save BexTuychiev/c54bc613c736073b4aba04a89dd0e263 to your computer and use it in GitHub Desktop.
Save BexTuychiev/c54bc613c736073b4aba04a89dd0e263 to your computer and use it in GitHub Desktop.
# Importing matlab files
import scipy.io
import pandas as pd
filename = "ja_data2.mat"
matlab = scipy.io.loadmat(filename)
print(type(matlab)) # prints out 'class <dict>'
# Saving DataFrames as MATLAB files
# Read any csv file
df = pd.read_csv('sample.csv')
# Rename DataFrame columns to suit them into MATLAB's file structures
df.rename(columns=lambda x: 'col_' + x.replace(' ', '_'), inplace=True)
scipy.io.savemat('new_matlab_name.mat', {'struct': df.to_dict('list')})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment