鸣叫提取@mentions我有一个CSV文件是这样的使用的findall蟒蛇(给出不正确的结果)
text
RT @CritCareMed: New Article: Male-Predominant Plasma Transfusion Strategy for Preventing Transfusion-Related Acute Lung Injury... htp://…
#CRISPR Inversion of CTCF Sites Alters Genome Topology & Enhancer/Promoter Function in @CellCellPress htp://.co/HrjDwbm7NN
RT @gvwilson: Where's the theory for software engineering? Behind a paywall, that's where. htp://.co/1t3TymiF3M #semat #fail
RT @sciencemagazine: What’s killing off the sea stars? htp://.co/J19FnigwM9 #ecology
RT @MHendr1cks: Eve Marder describes a horror that is familiar to worm connectome gazers. htp://.co/AEqc7NOWoR via @nucAmbiguous htp://…
我想提取所有提及(以“@”)从鸣叫文本。到目前为止,我已经做到了这一点
import pandas as pd
import re
mydata = pd.read_csv("C:/Users/file.csv")
X = mydata.ix[:,:]
X=X.iloc[:,:1] #I have multiple columns so I'm selecting the first column only that is 'text'
for i in range(X.shape[0]):
result = re.findall("(^|[^@\w])@(\w{1,25})", str(X.iloc[:i,:]))
print(result);
有两个问题在这里: 第一:在str(X.iloc[:1,:])
它给了我['CritCareMed']
这也不行,因为它应该给我['CellCellPress']
,在str(X.iloc[:2,:])
再次给了我['CritCareMed']
这是当然不会再罚款。最后的结果,我得到的是
[( ' ' 'CritCareMed'),('', 'gvwilson'),(””, 'sciencemagazine')]
一点也没有不包括第二排的提及和最后一排的两个提及。 我想应该是这个样子:
我怎样才能取得这些成果?这只是一个示例数据,我的原始数据有很多推文,所以方法好吗?
如何从df中选择第一列?如果iloc给出数据帧。在我的文件中有多个列,并且必须仅处理第一列,即'text' – melissa
要选择第一列,您可以使用列名,即'df.text','df ['text'] '或使用'iloc','df.iloc [:,0]'。 – Psidom