Skip to content

Instantly share code, notes, and snippets.

@stevenferrer
Forked from hernamesbarbara/numpy-opttheta.mat
Created February 12, 2018 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenferrer/f708d2920a5ae7920b6f603a60bfdc76 to your computer and use it in GitHub Desktop.
Save stevenferrer/f708d2920a5ae7920b6f603a60bfdc76 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