【问题标题】:How to display non numeric values from data frame如何从数据框中显示非数值
【发布时间】:2017-06-12 09:19:03
【问题描述】:

数据框:

Measure|Value
-------|----
A|1000
B|1000/
C|1000*
D|10
E|1000 0
F|1000
G|5..
H|2
I|w
K|288
L|
M|565

结果:

Measure|Value
-------|----
B|1000/
C|1000*
D|10
E|1000 0
G|5..
I|w
L|

在 SQL 中我使用查询:

select Measure,Value from dataframe where isnumeric(value)=0 or patindex('%[^0-9.-]%', value)!=0

如何在python中显示数据框中的非数值?

【问题讨论】:

标签: python pandas dataframe


【解决方案1】:

使用str.isdigit~ 反转布尔掩码:

In[6]: df.loc[~df['Value'].astype(str).str.isdigit()]

Out[6]:
   Measure   Value
1        B   1000/
2        C   1000*
4        E  1000 0
6        G     5..
8        I       w
10       L     NaN

如果列的dtype 已经是str,则不需要astype(str) 调用

【讨论】:

  • 我不明白你的评论,这个答案是你想要的
  • @Linus 很抱歉,但要求用户查看另一个问题在 SO 上是不礼貌的,SO 不是论坛,您已经对该问题有一个公认的答案,那么问题是什么?
猜你喜欢
  • 1970-01-01
  • 2020-08-03
  • 2017-07-08
  • 2021-09-15
  • 1970-01-01
  • 2013-07-11
  • 2016-08-04
  • 1970-01-01
  • 2014-10-10
相关资源
最近更新 更多