我正在尝试从我所遵循的合同所需的存储库中转换大量.mat文件。我们正在使用python进行工作,我需要转换文件以对其执行各种统计测试。我正在尝试将其转换,但无法获得前进所需的最佳结果。
这是我到目前为止使用的代码...
import scipy.io
import pandas as pd
import numpy as np
data = scipy.io.loadmat("C:/Users/jered.willoughby/Desktop/PHM/PK31.mat")
df = pd.DataFrame.from_dict(data, orient='index')#.reset_index()
print(df)
#df.to_csv("C:/Users/jered.willoughby/Desktop/PHM/df.csv", index=False)
for column in df.columns:
for idx in df[column].index:
x = df.get_value(idx,column)
try:
x = x if type(x) == str else str(x).encode('utf-8','ignore').decode('utf-8','ignore')
df.set_value(idx,column,x)
except Exception:
print('encoding error: {0} {1}'.format(idx,column))
df.set_value(idx,column,'')
continue
df.to_csv("C:/Users/jered.willoughby/Desktop/PHM/df.csv", index=False)
这是输出的样子。...