2017-05-30 76 views
0

我在數據幀得到這個在大熊貓的數據幀如何刪除線基於特定的字符

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 

請幫忙。

+0

你能解釋數據框的佈局?你是什​​麼意思刪除「文本行」?如果我們刪除包含':'的行,那麼您提供的行也不會被刪除? –

+0

你應該兩次思考,你的文本可能有一個':',例如「關注:顧客說:bla bla」,如果這不是問題,給出的答案已經對它有好處 – api55

回答

1

你可以做的一件事就是將你的數據框中':'之後的句子分開。你可以通過從你的數據框創建一個系列來做到這一點。

讓我們說c是你的系列。

c=pd.Series(df['column']) 
s=[c[i].split(':')[1] for i in range(len(c))] 

通過這樣做,您將能夠將您的句子與冒號分開。

0

假設您想保留句子的第二部分,您可以使用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