Pandas Dataframe data filtering and slicing

Source: Internet
Author: User

Dataframe Data Filter--loc,iloc,ix,at,iat condition Filter Single condition filter Select a record with a value greater than N for the col1 column: data[data[' col1 ']>n] filters the col1 column for records with a value greater than N, but displays col2, Col3 column value: data[[' col2 ', ' col3 ']][data[' col1 ']>n] Select a specific row: Use the Isin function to filter records based on specific values. Filter col1 value equals record of element in list: Data[data.col1.isin (list) multi-criteria filtering can use & (and) and | (or) operator or a specific function to implement a multi-condition filter using & filtering col1 columns with values greater than n,col2 columns with values greater than M: data[(data[' col1 '] > N) & (data[' col2 '] > m)] Use NumPy's Logical_and function to accomplish the same function: Data[np.logical_and (data[' col1 ']> n,data[' col2 ']>m)] The index filter slice operation uses the slice operation to select a specific row: DATA[N:M] Incoming column name Select a specific column: data[[' col1 ', ' col2 ']] loc function when each column already has column name, use data [' col1 '] to choose to take out an entire column of data. If you know column names and index, you can choose. loc simultaneously row and column selection: Data.loc[index, ' colum_names '] iloc function

Use the method with the LOC function, but no longer enter the column name, but the index:data.iloc[row_index,col_index of the input column]

The functions of the IX function IX are more powerful, and the parameters can be either an index or a name, equivalent to the combination of Loc and iloc.  Note that you need to be unified when using, the index and name at the same time when the row is selected, as well as the index and name at the same time as the peer selection: data.ix[n:m,[' col1 ', ' col2 ']] but in the latest version, the IX function is not recommended for use The AT function quickly locates elements of Dataframe based on the specified row index and column label, supports only column names when selecting columns: Data.at[row_index, ' column_names '] The IAT function is the same as at, using only index parameters: Data.iat[row_index,column_index]

Pandas Dataframe data filtering and slicing

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.