簡體   English   中英

Pandas Dataframe 刪除所有以雙引號開頭的行

[英]Pandas Dataframe remove all rows that begin with a double quotation mark

我有以下 dataframe:

index        text        
0            Test1       
1            "Test2 and more text"      
2            "Test3 and other text     
3            Test4     

我想刪除那些以雙引號開頭的行。 結果應如下所示:

index        text        
0            Test1           
3            Test4     

我知道startswith ,但由於某種原因它對我不起作用。 這是我嘗試過的:

my_df = my_df[~my_df["text"].str.startswith("\"")]
my_df = my_df[~my_df["text"].str.startswith('"')]

你可以做

m=df.text.str[0].ne('"')
0     True
1    False
2    False
3     True
Name: text, dtype: bool
df=df[m]

使用正則表達式

my_df[~my_df["text"].str.contains("^\"")]

這可能有效

df = df[df['text'].str.match('.*\".*') == False]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM