1. In the dataframe of pandas, we often need to select the rows of a specified condition based on a property, at which point the Isin method is particularly effective.
Import pandas as PD
DF = PD. Dataframe ([[1,2,3],[1,3,4],[2,4,3]],index = [' One ', ' two ', ' three '],columns = [' A ', ' B ', ' C '])
print DF
# A B C
# One 1 2 3
# two 1 3 4
# three 2 4 3
Let's say we choose a row with a value of 1 in column A.
Mask = df[' A '].isin ([1]) #括号中必须为list
print Mask
# one true
# two True
# three False
# name:a, dtype:bool
print Df[mask]
# A B C
# one 1 2 3
# Two 1 3 4
The dataframe in 2.pandas how to sort by the first keyword, the second keyword, here you can use Sort_values, the old version of Sort_index.
Import pandas as PD
DF = PD. Dataframe ([[1,2,3],[2,3,4],[2,4,3],[1,3,7]],
index = [' One ', ' two ', ' three ', ' four '],columns = [' A ', ' B ', ' C ']]
print DF
# A B C
# one 1 2 3
# two 2 3 4
# Three 2 4 3
# four 1 3 7
df.sort_values (by=[' A ', ' B '],ascending=[0,1],inplace =true)
print DF
# A B C
# two 2 3 4
# three 2 4 3
# One 1 2 3
# four 1 3 7