您可以应用一个功能,以行方式测试您的DataFrame是否存在字符串,例如,说df是您的DataFrame
rows_with_strings = df.apply(
lambda row :
any([ isinstance(e, basestring) for e in row ])
, axis=1)
这将为您的DataFrame创建一个掩码,指示哪些行至少包含一个字符串.因此,您可以通过相对的掩码选择没有字符串的行
df_with_no_strings = df[~rows_with_strings]
.
例:
a = [[1,2],['a',2], [3,4], [7,'d']]
df = pd.DataFrame(a,columns = ['a','b'])
df
a b
0 1 2
1 a 2
2 3 4
3 7 d
select = df.apply(lambda r : any([isinstance(e, basestring) for e in r ]),axis=1)
df[~select]
a b
0 1 2
2 3 4