java mat转csv,如何使用python将复杂的.mat文件转换为csv

I am trying to convert a .mat file to csv using python. The code I am using is

import scipy.io

import numpy as np

data = scipy.io.loadmat("wiki.mat")

for i in data:

if '__' not in i and 'readme' not in i:

np.savetxt(("file.csv"),data[i],delimiter=',')

When ever I run this code, I get error as follows:

Traceback (most recent call last):

File "test.py", line 8, in

np.savetxt(("file.csv"),data[i],delimiter=',')

File "/Library/Python/2.7/site-packages/numpy/lib/npyio.py", line 1258, in savetxt

% (str(X.dtype), format))

TypeError: Mismatch between array dtype ('[('dob', 'O'), ('photo_taken', 'O'), ('full_path', 'O'), ('gender', 'O'), ('name', 'O'), ('face_location', 'O'), ('face_score', 'O'), ('second_face_score', 'O')]') and format specifier ('%.18e')

Please help me out with some working solution!

解决方案Save an array to a text file.

You can, unfortunately, only store a single numeric numpy array in a single file. Whereas your .mat file contains a structure:

>> fieldnames(imdb)

ans =

{

[1,1] = dob

[2,1] = photo_taken

[3,1] = full_path

[4,1] = gender

[5,1] = name

[6,1] = face_location

[7,1] = face_score

[8,1] = second_face_score

[9,1] = celeb_names

[10,1] = celeb_id

}

>> imdb.name(1)

ans =

{

[1,1] = Fred Astaire

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值