我正在使用SQL代码将其移动到python,我有一个A1 A1 0 0 1 1 0 0 0 0 2 2 2 2
A2 A2 0 0 1 1 1 1 1 1 0 0 2 2
A3 A3 0 0 1 2 1 1 1 1 0 0 2 2
A4 A4 0 0 1 1 1 1 0 0 0 0 2 2
条件,说明点是WHERE
我需要打印我的数据框,数据,以便有问题的一列,指向,包含所有Null的
例如
NULL
我想让它归还:
name: age: points:
Sean 12 3
Jack 14 0
Peter 11 2
David 16 0
Paul 15 0
任何帮助表示赞赏
答案 0 :(得分:3)
如果需要过滤器值为boolean indexing
,请使用0
:
df = pd.DataFrame({'points': {0: 3, 1: 0, 2: 2, 3: 0, 4: 0},
'name': {0: 'Sean', 1: 'Jack', 2: 'Peter', 3: 'David', 4: 'Paul'},
'age': {0: 12, 1: 14, 2: 11, 3: 16, 4: 15}})
print (df)
age name points
0 12 Sean 3
1 14 Jack 0
2 11 Peter 2
3 16 David 0
4 15 Paul 0
df1 = df.ix[df.points == 0,['name','age']]
print (df1)
name age
1 Jack 14
3 David 16
4 Paul 15
如果值为NaN
:
df = pd.DataFrame({'points': {0: 3, 1: np.nan, 2: 2, 3: np.nan, 4: np.nan},
'name': {0: 'Sean', 1: 'Jack', 2: 'Peter', 3: 'David', 4: 'Paul'},
'age': {0: 12, 1: 14, 2: 11, 3: 16, 4: 15}})
print (df)
age name points
0 12 Sean 3.0
1 14 Jack NaN
2 11 Peter 2.0
3 16 David NaN
4 15 Paul NaN
df1 = df.ix[df.points.isnull(),['name','age']]
print (df1)
name age
1 Jack 14
3 David 16
4 Paul 15