简体   繁体   English

按列值删除 Pandas DataFrame 中的行(文本)

[英]Drop rows in Pandas DataFrame by Column values (text)

I want to return a new dataframe by dropping a row from dataframe using their respective text values.我想通过使用它们各自的文本值从 dataframe 删除一行来返回一个新的 dataframe 。 And only keeping ones that are blank (or whitespace).并且只保留空白(或空格)。 So far I can only find ways of either dropping NA, NULLS, by index or complete column.到目前为止,我只能找到按索引或完整列删除 NA、NULLS 的方法。 Please suggest way(s) how can I achieve this result.请提出如何实现这一结果的方法。

Below is the value_count of column 'Category' -以下是“类别”列的 value_count -

                                4091
ZeroClicks                      1342
Duplicate                        257
ZeroClicksDuplicate              139
NoKeywordDuplicate                16
NoKeywordZeroClicksDuplicate      12
NoKeyword                          1
Name: Category, dtype: int64

try:尝试:

df.loc[df['col_containing_whitespace'].str.contains('^\s+$',na=False)] 

or或者

df.loc[df['col_containing_whitespace'].str.contains('^\s*$',na=False)] 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 根据匹配的列值与其他数据框的组合删除行熊猫 - Drop rows pandas based on combination of matched column values with other dataframe 如何在熊猫数据框中的列中删除带有“nan”的行? - how to drop rows with 'nan' in a column in a pandas dataframe? Pandas Dataframe - 按列值过滤 dataframe 行 - Pandas Dataframe - Filtering dataframe rows by column values python&pandas-删除行,其中列值是另一个DataFrame中的索引值 - python & pandas - Drop rows where column values are index values in another DataFrame 如何通过列值的条件删除 DataFrame 中的行 - How to Drop rows in DataFrame by conditions on column values 熊猫删除具有不同列值的不同行 - pandas drop diffrent rows with differing column values 如何随机删除Pandas数据框中的行,直到一列中值的数量相等? - How to randomly drop rows in Pandas dataframe until there are equal number of values in a column? 有效地删除 Pandas Dataframe 中的行,您需要首先标记列的文本以传递条件语句 - Efficiently drop rows in a Pandas Dataframe, where you need to tokenize the text of a column first in order to pass a conditional statement 将Pandas数据帧分组一列,根据另一列删除行 - Group Pandas dataframe by one column, drop rows based on another column 按多个列值过滤pandas数据帧行 - Filter pandas dataframe rows by multiple column values
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM