我正在開發一個作為輸入資料幀的應用程式。
許多資料框之一的示例可以是這樣的
df = pd.DataFrame({'store': ['Blank_A09', 'Control_4p','13_MEG3','04_GRB10','02_PLAGL1','Control_21q','01_PLAGL1','11_KCNQ10T1','16_SNRPN','09_H19','Control_6p','06_MEST'],
'quarter': [1, 1, 2, 2, 1, 1, 2, 2,2,2,2,2],
'employee': ['Blank_A09', 'Control_4p','13_MEG3','04_GRB10','02_PLAGL1','Control_21q','01_PLAGL1','11_KCNQ10T1','16_SNRPN','09_H19','Control_6p','06_MEST'],
'foo': [1, 1, 2, 2, 1, 1, 9, 2,2,4,2,2],
'columnX': ['Blank_A09', 'Control_4p','13_MEG3','04_GRB10','02_PLAGL1','Control_21q','01_PLAGL1','11_KCNQ10T1','16_SNRPN','09_H19','Control_6p','06_MEST']})
print(df)
store quarter employee foo columnX
0 Blank_A09 1 Blank_A09 1 Blank_A09
1 Control_4p 1 Control_4p 1 Control_4p
2 13_MEG3 2 13_MEG3 2 13_MEG3
3 04_GRB10 2 04_GRB10 2 04_GRB10
4 02_PLAGL1 1 02_PLAGL1 1 02_PLAGL1
5 Control_21q 1 Control_21q 1 Control_21q
6 01_PLAGL1 2 01_PLAGL1 9 01_PLAGL1
7 11_KCNQ10T1 2 11_KCNQ10T1 2 11_KCNQ10T1
8 16_SNRPN 2 16_SNRPN 2 16_SNRPN
9 09_H19 2 09_H19 4 09_H19
10 Control_6p 2 Control_6p 2 Control_6p
11 06_MEST 2 06_MEST 2 06_MEST
我需要檢查奇數列是否相同。我這樣做
# Select odd columns
df_odd = df.iloc[:,::2]
# Do a hash with these columns
pd.util.hash_pandas_object(df.T, index=False)
store 18266754969677227875
employee 18266754969677227875
columnX 18266754969677227875
dtype: uint64
我現在如何檢查這些哈希值是否相同?
uj5u.com熱心網友回復:
散列確保值的“順序”,因為不同的順序會給出不同的散列。
要檢查所有奇數列是否相同,您可以使用:
pd.util.hash_pandas_object(df.iloc[:,::2].T, index=False).nunique() == 1
輸出:True
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/486111.html
