有没有办法在包含一万个使用python编码的实例的数据帧中找到特殊符号,如“?”,“*”,“NA”?

如何使用python代码在数据框中查找特殊字符.并找到它们的位置。为此,我在python中使用正则表达式,但我没有得到任何东西。

如果每列包含特殊字符,则希望显示该列的文本。


郎朗坤
浏览 131回答 1
1回答

凤凰求蛊

考虑到以下作为输入数据帧,我已经执行了操作。    name    val0   a   11   *   22   b   NaN3   d   14   g   ?5   t   36   h   4import numpy as npimport pandas as pdf=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: '*'
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python