
我想獲得 corr 關系超過 0.2 且低于 0.8 的所有列名。有沒有辦法做到這一點?
uj5u.com熱心網友回復:
使用 pandas 檔案中的示例,我們可以使用兩個條件獲取 corr 和 filter,獲取匹配項的索引并輸出到串列。
import pandas as pd
def histogram_intersection(a, b):
v = np.minimum(a, b).sum().round(decimals=1)
return v
df = pd.DataFrame([(.2, .3), (.0, .6), (.6, .0), (.2, .1)],
columns=['dogs', 'cats'])
c = abs(df.corr(method=histogram_intersection)['cats'])
print(c)
print(c[(c>.2) & (c<.8)].index.tolist())
輸出
dogs 0.3
cats 1.0
Name: cats, dtype: float64
['dogs']
uj5u.com熱心網友回復:
您可以corList使用條件索引系列,并使用以下命令檢索名稱.index:
corList[(corList > 0.2) & (corList 0.8)].index
或者一個可能的更具可讀性的版本:
corList[corList.gt(0.2) & corList.lt(0.8)].index
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/402287.html
上一篇:pythonpandas:如何將多列合并為一列并使用餅圖
下一篇:字典理解-獲取資料框中每一列的值
