首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >根据行中的特定值删除行

根据行中的特定值删除行
EN

Stack Overflow用户
提问于 2022-03-16 15:17:54
回答 1查看 37关注 0票数 0
代码语言:javascript
复制
    Edition             Reviews               Ratings                     BookCategory                           Price          Edition_year
165   Paperback,– Import, 5 Jul 1996  4.5 out of 5 stars    2 customer reviews                           Sports  270.00         1996
166          Hardcover,– 18 Aug 2009  4.5 out of 5 stars    2 customer reviews  Language, Linguistics & Writing   61.00         2009
167          Paperback,– 26 Jul 2018  3.7 out of 5 stars   23 customer reviews        Crime, Thriller & Mystery  184.00         2018
168  Paperback,– Import, 22 Mar 2018  4.2 out of 5 stars   50 customer reviews                          Romance   70.00         2018
169     Paperback,– Abridged, Import  5.0 out of 5 stars    2 customer reviews               Action & Adventure  418.00         port
170          Paperback,– 10 Jan 2018  4.7 out of 5 stars    4 customer reviews                           Sports  395.00         2018
171             Paperback,– Apr 2011  4.0 out of 5 stars  197 customer reviews  Language, Linguistics & Writing  179.00         2011
172          Paperback,– 17 Feb 2009  5.0 out of 5 stars    2 customer reviews                  Comics & Mangas  782.00         2009
173          Paperback,– 22 Aug 2000  3.5 out of 5 stars    4 customer reviews  Language, Linguistics & Writing  475.44         2000
174           Paperback,– 5 Jan 2012  4.0 out of 5 stars   30 customer reviews                           Humour  403.00         2012

假设在这些dataframe中,在Edition_year列下,我希望删除版本年份的值不是数值的行。也就是说,有一些值是字符串。我已经尝试过.drop()方法,但不能满足所需的输出。

这就是我试过的:

代码语言:javascript
复制
df = df.drop(df[df['Edition_year'].apply(lambda x: str(x).isalpha())].index, inplace = True)
EN

回答 1

Stack Overflow用户

发布于 2022-03-27 13:46:12

您可以使用以下方法确定数值的Edition_year

代码语言:javascript
复制
numeric_filter = df.Edition_year.astype(str).str.isnumeric()

然后使用筛选器只选择所需的行。

代码语言:javascript
复制
df = df.loc[numeric_filter]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71499666

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档