使用多个matlab文件创建panda Dataframe

mxg2im7a  于 2022-12-27  发布在  Matlab
关注(0)|答案(1)|浏览(204)

我怎样才能同时读取、加载和转换多个.mat文件到python pandas Dataframe 中?
尝试用.mat文件制作panda Dataframe

7d7tgy0s

7d7tgy0s1#

import glob
import scipy.io
import pandas as pd

# Get a list of all .mat files in the current directory
mat_files = glob.glob("*.mat")

# Initialize an empty list to store the data
data = []

# Loop through each .mat file
for file in mat_files:
    # Load the .mat file using scipy.io.loadmat
    mat = scipy.io.loadmat(file)
    
    # Extract the data from the .mat file
    data.append(mat['data'])

# Create a Pandas dataframe from the data
df = pd.DataFrame(data)

# Print the dataframe
print(df)

相关问题