是否有标准方法将matlab.mat(matlab格式的数据)文件转换为Panda DataFrame

我知道使用scipy.io可以解决问题,但我想知道是否有一种简单的方法可以做到这一点.

推荐答案

我找到了两种方法:scipy或mat4py.

  1. mat4py

从MAT文件加载数据

函数loadmat将MAT文件中存储的所有变量加载到

示例:将MAT文件加载到Python数据 struct 中:

data = loadmat('datafile.mat')

发件人:

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

  1. Scipy:

示例:

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)

发件人:

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

  1. 最后,您可以使用PyHogs,但仍可以使用scipy:

正在读取复杂的.mat个文件.

本笔记本显示了一个读取Matlab.mat文件的示例, 使用循环将数据转换为可用的字典,这是一个简单的图 数据的一部分.

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

Database相关问答推荐

数据库是序列图中的控制器还是边界?

数据库 struct 建议

如何使用 SQL Server 中的round方法将浮点数转换为 int?

将光标中找到的值输出到logcat?

502 是数据库错误的适当状态代码吗?

从 DbDataReader 读取数据的最快方法是什么?

nodejs和数据库如何通信 ?

sql server:在必要时在外键上创建索引

C# 连接到数据库并列出数据库

将 `tsv` 文件插入 postgresql 数据库

将实体框架中的字符串列映射到枚举

Django 数据库值的最佳推荐方式是什么?

Hibernate如何连接多个数据库

谁有维基数据库?

Android - ViewHolder 模式是否在 CursorAdapter 中自动实现?

Django + PostgreSQL:如何重置主键?

为什么 DBMS 不支持 ASSERTION

分离实体和被管理实体

DBMS中数据模型和数据库模式的区别?

如何使用 liquibase,一个具体的例子