import pandas as pd
d={
'name':['a','n','c','d','e','f'],
'Gender':['male','female','male','male','female','female'],
'age':[23,24,24,22,21,20],
'hight':[173,174,164,172,161,160],
'weight1':[53,74,44,62,71,60],
'weight2':[53,64,54,66,81,50]
}
df=pd.DataFrame(d)
df
|
name |
Gender |
age |
hight |
weight1 |
weight2 |
0 |
a |
male |
23 |
173 |
53 |
53 |
1 |
n |
female |
24 |
174 |
74 |
64 |
2 |
c |
male |
24 |
164 |
44 |
54 |
3 |
d |
male |
22 |
172 |
62 |
66 |
4 |
e |
female |
21 |
161 |
71 |
81 |
5 |
f |
female |
20 |
160 |
60 |
50 |
df[df.age==24]
|
name |
Gender |
age |
hight |
weight1 |
weight2 |
1 |
n |
female |
24 |
174 |
74 |
64 |
2 |
c |
male |
24 |
164 |
44 |
54 |
df[(df.age==24 )&( df.hight ==174)]
|
name |
Gender |
age |
hight |
weight1 |
weight2 |
1 |
n |
female |
24 |
174 |
74 |
64 |
df.query("age==24")
|
name |
Gender |
age |
hight |
weight1 |
weight2 |
1 |
n |
female |
24 |
174 |
74 |
64 |
2 |
c |
male |
24 |
164 |
44 |
54 |
df.query("age==24").query('hight==174')
|
name |
Gender |
age |
hight |
weight1 |
weight2 |
1 |
n |
female |
24 |
174 |
74 |
64 |
df.query('index > 2')
|
name |
Gender |
age |
hight |
weight1 |
weight2 |
3 |
d |
male |
22 |
172 |
62 |
66 |
4 |
e |
female |
21 |
161 |
71 |
81 |
5 |
f |
female |
20 |
160 |
60 |
50 |
df.query('Gender =="male" and name =="a"')
|
name |
Gender |
age |
hight |
weight1 |
weight2 |
0 |
a |
male |
23 |
173 |
53 |
53 |
df.query('Gender =="male" and age<24')
|
name |
Gender |
age |
hight |
weight1 |
weight2 |
0 |
a |
male |
23 |
173 |
53 |
53 |
3 |
d |
male |
22 |
172 |
62 |
66 |
import numpy as np
grade = np.array([1, 3, 4, 5, 0, 2, -1])
grade
array([ 1, 3, 4, 5, 0, 2, -1])
grade1 = np.where(grade > 3)
grade1
(array([2, 3], dtype=int32),)
grade1 = np.where(grade > 3, 'high', 'low')
grade.argmin()
6
grade.argmax()
3
grade.argsort()
array([6, 4, 0, 5, 1, 2, 3], dtype=int32)
grade = np.array([1, 3, 4, 5, 0, 2, -1])
grade1 = np.array([1, 3, 4, 5])
np.intersect1d(grade, grade1)
array([1, 3, 4, 5])