matlab数据文件到pandas DataFrame

拉蒙·马丁内斯(Ramon Martinez)

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

我知道可以通过使用一种解决方法,scipy.io但我想知道是否有一种直接的方法。

德斯特里夫

我发现了两种方式:scipy或mat4py。

  1. mat4py

从MAT文件加载数据

loadmat函数仅使用Python的dict和list对象将存储在MAT文件中的所有变量加载到简单的Python数据结构中。数字和单元格数组将转换为按行排序的嵌套列表。压缩数组以消除仅包含一个元素的数组。结果数据结构由与JSON格式兼容的简单类型组成。

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

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Pandas DataFrame:将数据扩展到整个月

来自分类Dev

将分号数据字典到Pandas Dataframe

来自分类Dev

将 Pandas Dataframe 中的一行数据输入到 csv 文件中的下一个空行

来自分类Dev

python:多列pandas数据文件

来自分类Dev

Python字典到Pandas Dataframe

来自分类Dev

转换Pandas DataFrame到字典

来自分类Dev

从字典列表到Pandas DataFrame

来自分类Dev

从Spark到Pandas Dataframe迭代

来自分类Dev

模式表到 Pandas DataFrame

来自分类Dev

Pandas Panel 到 DataFrame 索引

来自分类Dev

从 Pandas Dataframe 到 Javascript 数组

来自分类Dev

Spark DataFrame 到 xml 文件

来自分类Dev

Pandas DataFrame高效移动数据

来自分类Dev

Pandas DataFrame高效移动数据

来自分类Dev

来自文件的python pandas dataframe

来自分类Dev

将数百个数据文件组合到单个主DataFrame中的有效方法是什么?

来自分类Dev

使用Matlab可靠地读取列表数据文件

来自分类Dev

在Matlab中自动读取包含特殊字符的数据文件

来自分类Dev

Matlab的包装程序,用于读取稀疏数据文件

来自分类Dev

从多个文件中读取多个CSV文件到pandas DataFrame中

来自分类Dev

列表框项目到数据文件C#

来自分类Dev

Symfony - xml 到 json,大数据文件

来自分类Dev

使用 PyInstaller 将数据文件打包到 EXE 中

来自分类Dev

pyspark中的Pandas DataFrame到配置单元

来自分类Dev

JSON字典到Python中的Pandas DataFrame

来自分类Dev

Python dict到DataFrame Pandas-级别

来自分类Dev

Pandas DataFrame-行到列的字典

来自分类Dev

Pandas DataFrame到列表列表的字典

来自分类Dev

分类嵌套列表到Pandas DataFrame中