2017-05-30 46 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