1 回答
TA贡献1825条经验 获得超4个赞
考虑到以下作为输入数据帧,我已经执行了操作。
name val
0 a 1
1 * 2
2 b NaN
3 d 1
4 g ?
5 t 3
6 h 4
import numpy as np
import pandas as pd
f=pd.read_csv('data_file.csv')
f=pd.DataFrame(f)
#the below loop will provide you with the location of null values. i.e. "NaN"
for i,j in zip(*np.where(pd.isnull(f))):
print("{},{}".format(i,j))
o/p: 2,1
#similarly finding location of '*' and '?'
special=['*','?']
for k in special:
print(np.where(f.applymap(lambda x: x == k)),'location for ',k)
o/p:
(array([1], dtype=int64), array([0], dtype=int64)) location for *
(array([4], dtype=int64), array([1], dtype=int64)) location for ?
eg:
i/n: f.iloc[1,0]
o/p: '*'
添加回答
举报