[英]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.