Pandas implementing a row that selects a specific index

Source: Internet
Author: User
The following for you to share a pandas implementation of the selection of a specific index of the row, has a good reference value, I hope to be helpful to everyone. Come and see it together.

As shown below:

>>> Import numpy as np>>> import pandas as pd>>> Index=np.array ([2,4,6,8,10]) >>> Data=np.array ([3,5,7,9,11]) >>> DATA=PD. DataFrame ({' num ':d ata},index=index) >>> print (data)  num2   910  11> >> select_index=index[index>5]>>> Print (select_index) [6 8 10]>>> data[' num '].loc[select_ Index]6   910  11name:num, dtype:int32>>>

Note that you cannot use Iloc,iloc to access a sequence as an array, and the subscript starts at 0:

>>> data[' num '].iloc[2:5] 6   7 8   9  name:num, dtype:int32 >>> data[' num '].iloc[[2 , 3,4]] 6   7 8   9  name:num, Dtype:int32 >>>

Related Article

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.