A detailed description of the Isin function in pandas

Source: Internet
Author: User
Tags true true

Original link: http://www.datastudy.cc/to/69

Today, a classmate asked, "Not in the logic, want to use the SQL select c_xxx_s from t1 the left join T2 on T1.key=t2.key where T2.key is NULL logic in Python to implement the Left join (directly with the Join method), but do not know how to implement where key is NULL.

In fact, the implementation of the logic of not in, do not be so complex, directly with the Isin function to take the inverse can be, the following is the Isin function of the detailed.

Import Pandas;

DF = Pandas. DataFrame ({

' A ': [1, 2, 3],

' B ': [' A ', ' B ', ' F ']

})

#如果是一个序列或者数组,

#那么判断该位置的值, whether in the entire sequence or array

Df.isin (

[1, 3, +, ' a ']

)

A B

0 true True

1 false false

2 True False

DF = Pandas. DataFrame ({

' A ': [1, 2, 3],

' B ': [1, 4, 7]

})

#如果是一个dirt,

#那么就会首先判断对应的index是否存在,

#如果存在, the corresponding position is determined, if the column exists

Df.isin ({

' A ': [1, 3],

' B ': [4, 7, 12]

})

A B

0 True False

1 False True

2 True True

#如果不存在, then all is false, for example, column B is not, then all is False

Df.isin ({

' A ': [1, 3],

' C ': [4, 7, 12]

})

A B

0 True False

1 false false

2 True False

DF = Pandas. DataFrame ({

' A ': [1, 2, 3],

' B ': [' A ', ' B ', ' F ']

})

other = Pandas. DataFrame ({

' A ': [1, 3, 3, 2],

' B ': [' e ', ' f ', ' f ', ' e ']

})

#如果是一个DataFrame,

#首先就是列名要存在,

#并且需要df中行列位置和B对应的行列位置一一匹配 to return True

Df.isin (Other)

A B

0 True False

1 false false

2 True True

other = Pandas. DataFrame ({

' C ': [1, 3, 3, 2],

' D ': [' e ', ' f ', ' f ', ' e ']

})

#因为AB列皆不在, so all is False

Df.isin (Other)

A B

0 false false

1 false false

2 false false

Yes, yes? Not yet mentioned in? Oh, no isnotin function, the inverse method is to add a ~ in front of the function, a good ecstasy of a floating.

~df.isin (Other)

650) this.width=650; "src=" Http://www.datastudy.cc/img/6067b5a7d924fdf98823cbb3d6b4e771/0.jpg "style=" width : 393.107px; "alt=" 0.jpg "/>


A detailed description of the Isin function in pandas

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.