[英]How to drop a row in Pandas only if it exists in the DataFrame
[英]How to drop a row in pandas dataframe if there is only word in a pandas column
如果列中有一個只有一個單詞的項目,我們如何在 Pandas 數據幀上刪除整行
例子:
'the cat likes mice',
'the dog likes the cat',
'dog'
返回
'the cat likes mice',
'the dog likes the cat'
如何使用pd.Series.str.contains
方法查找空格:
df = pd.DataFrame({'items': ['the cat likes mice',
'the dog likes the cat',
'dog']})
df = df[df['items'].str.contains(' ')]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.