python學習第十六天集合的關係測試

來源:互聯網
上載者:User

標籤:分析   nbsp   bsp   測試   com   關係   inter   section   集合   

在做資料分析的時候,要對一個集合分析,而且分析多個集合的之間的關係分析,那麼用傳統的迴圈的比較麻煩,集合提供很多方法,很容易比較多個集合的關係,並集,交集,差集,對稱差集等。

n1={1,2,4,6}

n2={2,3,5,6}

1,交集的用法

n3=n1.intersection(n2)

n3={2,6}

或者 n3=n1&n2

2,差集的用法

n1的差集

n1.difference(n2)

n2.difference(n1)

或者 n1-n2 ,n2-n1

3,並集的用法

n1.union(n2)

或者 n1 | n2

4,對稱的差集

   求出交集的相反的值

n1.symmetric_difference(n2)  n1 ^ n2 

快樂學習,每天進步一點點 文章來自(玖樂網路 http://www.96net.com.cn/)

python學習第十六天集合的關係測試

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.