![](/img/trans.png)
[英]Remove a row in a pandas data frame if the data starts with a specific character
[英]How to remove lines in pandas data frame based on specific character
我在數據框中得到了這個
name : john,
address : Milton Kings,
phone : 43133241
Concern:
customer complaint about the services is so suck
thank you
我怎樣才能處理上述以僅除去文本行中包含數據幀:
? 我的目標是獲得僅包含以下內容的行。
customer complaint about the services is so suck
請幫助。
您可以做的一件事是將“:”后面的句子與數據框分開。 您可以通過在數據框中創建一系列序列來實現。
假設c是您的系列。
c=pd.Series(df['column'])
s=[c[i].split(':')[1] for i in range(len(c))]
這樣,您就可以將句子與冒號分開。
假設您想保留句子的第二部分,則可以使用applymap方法來解決您的問題。
import pandas as pd
#Reproduce the dataframe
l = ["name : john",
"address : Milton Kings",
"phone : 43133241",
"Concern : customer complaint about the services is so suck" ]
df = pd.DataFrame(l)
#split on each element of the dataframe, and keep the second part
df.applymap(lambda x: x.split(":")[1])
輸入:
0
0 name : john
1 address : Milton Kings
2 phone : 43133241
3 Concern : customer complaint about the services is so suck
輸出:
0
0 john
1 Milton Kings
2 43133241
3 customer complaint about the services is so suck
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.