Bol*_*boa 4 python dataset dataframe python-3.x pandas
我有一个巨大的数据集,包含数千行和数百列。其中一列包含一个字符串,因为我收到错误。我想找到这个字符串。我的所有列都应该是浮点值,但是其中一列str在某处有一个类型。
如何使用Pandas并仅打印类型的行循环遍历特定列str?我想找出字符串是什么,以便我可以将它们转换为等效的数字。
applymap与使用type
df = pd.DataFrame({'C1': [1,2,3,'4'], 'C2': [10, 20, '3',40]})
df.applymap(type)==str
Out[73]:
C1 C2
0 False False
1 False False
2 False True
3 True False
Run Code Online (Sandbox Code Playgroud)
在这里你就知道了str细胞。然后我们用np.where它来定位它
np.where((df.applymap(type)==str))
Out[75]: (array([2, 3], dtype=int64), array([1, 0], dtype=int64))
Run Code Online (Sandbox Code Playgroud)