我似乎无法找到正确的语法。我的代码加载了一个文件" sensordata.mat"这被称为" temps",并将其用于结果。在代码的最后,它应该将我的数据写入csv文件。我尝试了以下方法:
DF.ix["A"] = DF.ix["A"] + pd.Series([4,5,6,7],name="A",index=list("defg"))
这只会给我一个错误说明:#!/usr/bin/python
import pandas as pd
X = [[1,2,3],[-1,-2,-3]]
r_labels = ["A","B"]
c_labels = ["a","b","c"]
DF = pd.DataFrame(X)
DF.index = r_labels
DF.columns = c_labels
#I want to add columns [d,e,f,g] to each row
row1 = [('d', 4), ('e', 5), ('f', 6), ('g', 7)]
row2 = [('d', -4), ('e', -5), ('f', -6), ('g', -7)]
DF_tmp = pd.DataFrame()
for r_label,row in zip(DF.index,[row1,row2]):
SR_row = pd.Series([x[1] for x in row],name=r_label,index=[x[0] for x in row])
DF_tmp = DF_tmp.append(SR_row)
DF = pd.concat([DF, DF_tmp], axis=1, join_axes=[DF.index])#, how='outer', on=DF_tmp.columns)
有谁知道这方面的解决方案?感谢您的专业知识。
答案 0 :(得分:0)
CSV支持内置于MATLAB中:
csvwrite('sensordata.csv', temps);