如何过滤python中存在字符串值的值?

如何过滤python中存在字符串值的值?,python,regex,python-3.x,pandas,python-2.7,Python,Regex,Python 3.x,Pandas,Python 2.7,我曾说过: Numbers String AlphaNumString 0 123 sea sea123 1 456 sky sky456 3 456' sky1 nuts 4 Nan tea3 45tea 5 562 656 L2.36 6 896 light 5642 7 s456 Nan Nan

我曾说过:

   Numbers   String   AlphaNumString
0   123       sea       sea123
1   456       sky       sky456
3   456'      sky1      nuts
4   Nan       tea3      45tea
5   562       656       L2.36
6   896       light     5642
7   s456      Nan       Nan
8   963       lf56      pe562
9   456%      per       per789
10  Nan       456       123k
输出:df1 过滤掉
Numbers
列中包含纯数值或
Nan
的行

   Numbers   String   AlphaNumString
0   123       sea       sea123
1   456       sky       sky456
2   Nan       tea3      45tea
3   562       656       L2.36
4   896       light     5642
5   963       lf56      pe562
6   Nan       456       123k

不需要使用正则表达式

只运行
df[df.Numbers.isna()| df.Numbers.str.isnumeric()]
,即选择行 其中数字列:

  • 要么是楠,
  • 或者内容可转换为数字
但是如果你想“限制”允许的数值为整数, 将此表达式更改为:

df[df.Numbers.isna() | df.Numbers.str.isdigit()]

如果您发布代码和遇到的问题DDF[~df.Numbers.str.contains(r'[a-zA-Z]'),我会更容易提供帮助。我正在使用这段代码,但问题是,这段代码排除了Nan,还保留了类似456的字符串值。我相信isdigit()函数对浮点数据类型不起作用。对于浮点数据类型,它不起作用。但此列也包含字母,因此它是od对象类型。实际上,更通用的解决方案是首先检查列类型。如果类型为float,则应返回所有行。