2016-07-05 20 views
7

matlab.mat (matlab biçimlendirilmiş veri) dosyalarını Panda DataFrame'a dönüştürmenin standart bir yolu var mı?pandalar için matlab veri dosyası DataFrame

scipy.io kullanarak bir geçici çözüm olabileceğinin farkındayım, ancak bunu yapmanın basit bir yolu olup olmadığını merak ediyorum.

cevap

8

2 yol buldum: scipy veya mat4py. MAT-dosyadan

  1. mat4py

Yük verileri

fonksiyon loadmat yükleri sadece Python'un dict kullanarak bir basit Python veri yapısına MAT-dosyasında saklanan tüm değişkenleri ve nesneleri listelenir. Sayısal ve hücre dizileri satır sıralı iç içe geçmiş listelerine dönüştürülür. Diziler sadece bir elemanla dizileri yok etmek için sıkıştırılır. Ortaya çıkan veri yapısı, JSON biçimiyle uyumlu gibi basit türlerden oluşur.

Örnek:

data = loadmat('datafile.mat') 

: From: Python veri yapısı içine MAT-dosyayı yükleyin

https://pypi.python.org/pypi/mat4py/0.1.0

  • scipy
      :

    Örnek:

    import numpy as np 
    from scipy.io import loadmat # this is the SciPy module that loads mat-files 
    import matplotlib.pyplot as plt 
    from datetime import datetime, date, time 
    import pandas as pd 
    
    mat = loadmat('measured_data.mat') # load mat-file 
    mdata = mat['measuredData'] # variable in mat file 
    mdtype = mdata.dtype # dtypes of structures are "unsized objects" 
    # * SciPy reads in structures as structured NumPy arrays of dtype object 
    # * The size of the array is the size of the structure array, not the number 
    # elements in any particular field. The shape defaults to 2-dimensional. 
    # * For convenience make a dictionary of the data using the names from dtypes 
    # * Since the structure has only one element, but is 2-D, index it at [0, 0] 
    ndata = {n: mdata[n][0, 0] for n in mdtype.names} 
    # Reconstruct the columns of the data table from just the time series 
    # Use the number of intervals to test if a field is a column or metadata 
    columns = [n for n, v in ndata.iteritems() if v.size == ndata['numIntervals']] 
    # now make a data frame, setting the time stamps as the index 
    df = pd.DataFrame(np.concatenate([ndata[c] for c in columns], axis=1), 
            index=[datetime(*ts) for ts in ndata['timestamps']], 
            columns=columns) 
    

    Gönderen:

    http://poquitopicante.blogspot.fr/2014/05/loading-matlab-mat-file-into-pandas.html

    1. Son olarak PyHogs kullanmak ancak yine scipy kullanabilirsiniz: Karmaşık .mat dosyaları okuma

    .

    Bu defter, bir Matlab .mat dosyası, veriyi, döngülerle kullanılabilir bir sözlüğe dönüştüren bir örneği gösterir, verilerin basit bir grafiğini .

    http://pyhogs.github.io/reading-mat-files.html

  • +0

    Mükemmel bir çözüm:
    Eğer matlab engine kullanma scipy

    import scipy.io as sio test = sio.loadmat('test.mat') 

    belirtildiği gibi. Bu cevap seçilmelidir. – Jack

    4

    Yolları bunu:

    import matlab.engine 
    eng = matlab.engine.start_matlab() 
    content = eng.load("example.mat",nargout=1)