如何显示数据帧中的非数值

2024-05-05 10:16:54 发布

您现在位置:Python中文网/ 问答频道 /正文

数据帧:

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

结果:

^{pr2}$

在SQL中,我使用查询:

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

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


Tags: or数据fromdataframesqlvaluewhereselect
0条回答
网友
1楼 · 发布于 2024-05-05 10:16:54

使用^{}~反转布尔掩码:

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)调用

相关问题 更多 >