如何获得仅列出绝对值相关性大于.7?
的变量的输出我希望输出类似于:
std::vector<std::vector<Element>> bmpcolrow(m_width, std::vector<Element>(m_height));
for(int i = 0; i < m_height; i++) {
fread(data, sizeof(unsigned char), row_padded, f);
for(int j = 0; j < m_width; j++) {
// BGRA format
Element element;
element.Elements[0] = data[3*j+2];
element.Elements[1] = data[3*j+1];
element.Elements[2] = data[3*j];
element.Elements[3] = 0; // for alpha
bmpcolrow[j][m_height-i-1] = element;
}
}
for (const auto& col : bmpcolrow)
m_pixelVec.insert(m_pixelVec.end(), col.begin(), col.end());
谢谢你的时间!
代码
four: one, three
one: three
输出
import pandas as pd
x={'one':[1,2,3,4],'two':[3,5,7,5],'three':[2,3,4,9],'four':[4,3,1,0],}
y=pd.DataFrame(x)
print(y.corr())
答案 0 :(得分:1)
如果您想要打印出来,这将有效:
col_names = y.corr().columns.values
for col, row in (y.corr().abs() > 0.7).iteritems():
print(col, col_names[row.values])
请注意,这可行,但可能会很慢,因为iteritems
方法会将每一行转换为一系列。
答案 1 :(得分:1)
这对我有用:
corr = y.corr().unstack().reset_index() #group together pairwise
corr.columns = ['var1','var2','corr'] #rename columns to something readable
print( corr[ corr['corr'].abs() > 0.7 ] ) #keep correlation results above 0.7
您可以通过将最后一行更改为
来进一步排除具有相同名称(corr = 1)的变量print( corr[ (corr['corr'].abs() > 0.7) & (corr['var1'] != corr['var2']) ] )