Skip to content

Instantly share code, notes, and snippets.

@hernamesbarbara
Last active March 18, 2019 16:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hernamesbarbara/8197854 to your computer and use it in GitHub Desktop.
Save hernamesbarbara/8197854 to your computer and use it in GitHub Desktop.
How to import structured matlab data into python with scipy | prototype | http://bit.ly/1cdqxQc
import pandas as pd
from scipy.io import loadmat
dot_mat_file = 'numpy-opttheta.mat'
data = loadmat(dot_mat_file)
print type(data) # ==> Out[9]: dict
print '*' * 79
for key in data.keys():
print key,' ', type(data[key])
print '*' * 79
df = pd.DataFrame(data['opttheta'], columns=['opt_theta'])
nrow, ncol = df.shape
print 'nrow: %d' % nrow
print 'ncol: %d\n' % ncol
print df.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment