我有一个数据框架,在一列中,我有一个全文,其中有多个非常长的句子。我使用NLTK对文本进行标记化,但现在我需要确保只从给定的完整单词的长列表中提取包含任意单词的句子。我写了下面的代码,但它的问题是,它不是作为一个整体检查文本中的单词,而是例如在搜索列表中找出一个给定的单词,比如'tic',它选择一个包含单词‘统计’的句子。
symptoms = [long list of words ~ about 100]
new_df = df[df['Sentence'].str.contains('|'.join(symptoms))]
就在这段代码之上
我正在使用pandas (Python)从excel表格中提取一些数据。目前,我已经编写了一个代码,它遍历每一列,如果它找到一个文本,它会返回整个列:
def getTextData(self, dataframe, getText):
for col in dataframe:
for cellvalue in dataframe[col]:
if getText == cellvalue:
#print dataframe[col]
re
在这里,我尝试分析和练习pandas.dataframe函数。现在,我正在尝试删除在给定的链接列中没有特定单词的所有行。 ? 您可以在给定的链接图像列表中看到。如果链接中出现"Microsoft“以外的内容,我需要删除整行。在本例中,我需要删除(4,6,7,9,13,14,16)行。 df = pd.DataFrame.from_dict(df_dictnew)
for j in df_dictnew['post_link']:
i = j.split('/')[3]
#print(i)
if i != "Micro
我在python中有以下数据帧,它们是列表的一部分。 dataframe_list= []## CREATE AN EMPTY LIST
import pandas as pd
A=pd.DataFrame()
A["name"]=["A", "A", "A"]
A["att"]=["New World", "Hello", "Big Day now"]
B=pd.DataFrame()
B["name"]=["A2", "A
我有一个dataframe,基于名为"originator“的列中的字符串,我想检查该字符串是否有驻留在另一个列表中的单词。如果字符串中有一个位于上述列表中的单词,则将列originator_prediction更新为"org“。 有没有更好的方法来做这件事?我用下面的方法做了,但是很慢。 for row in df['ORIGINATOR'][1:]:
string = str(row)
splits = string.split()
for word in splits:
if word in COMMON_ORG_
我有一个字符串列表,需要对数据框架中的某一列进行搜索:
search_strings = ['foo bar', 'bar such foo', 'very wow foo']
我试图在dataframe中检索与列表中每个字符串中的单词按任何顺序匹配的行。dataframe可能如下所示:
ID string_col
1 foo bar
2 bar foo
3 foo very bar
4 bar such foo
5 foo wow very
我很高兴地发现,我可以在str.contains中使用一个‘AC.26’操作符(检索所有5行)
我正在尝试对数据帧进行分段,其中只有一个数据帧在它的一列中包含某些单词,而不包含其他单词。 例如 d = {'resolution' : ['replaced scanner', 'replaced the scanner for the user with a properly working one from the cage replaced the wire on the damaged one and stored it for later use','the scanner has been replaced and the
我有一个包含一些文本列的dataframe df: texts
This is really important(actually) because it has really some value
This is not at all necessary for it @ to get that 我想执行一次搜索,并获得关键字为"important(actually)“的文本,但似乎不起作用。 我该如何获取这些信息呢?我使用了以下代码: df_filter=df[df.apply(lambda x: x.astype(str).str.contains(keyword, flags
我的DataFrame有两列:
Name Status
a I am Good
b Goodness!!!
c Good is what i feel
d Not Good-at-all
我想过滤行,其中的状态有一个字符串'Good‘作为它的确切单词,而不是与任何其他单词或字符组合。
因此,输出将是:
Name Status
a i am Good
c Good is what i feel
另外两行中有一个“好”字符串,但与其他字符混合,因此不应该被选中。
我试着做:
d = df[df['Status'].str.co
好的,我在列表中有一个停用词列表,我想删除DataFrame中的行,这些行可能出现在包含字符串的列中的任何位置。 wordlist = ['hello','goodbye','you']
column1 column2
this is me 10
how are you? 15
Goodbye Jim 20
Hello you 25 下面是我想要结束的内容,其中删除了包含单词列表中找到的行的行 column1 column2
this is me
我有一个有3列的dataframe,我想删除所有行,其中包含字符串(搜索键)的一部分。
我的数据帧:
user_name user_first_name user_email
Max Mustermann max.musterman@gmail.com
Tom Hans tom.musterman@web.de
Tom1 Hans1 tom.musterman@test.de
我的搜索关键词是:@gmail.com,@web
如果一列包含换行符和后面跟的特定单词,我会尝试返回行。所以“\n单词”。 下面是一个最小的例子 testdf = pd.DataFrame([['test1', ' generates the final summary. \nRESULTS We evaluate the performance of ', ], ['test2', 'the cat and bat \n\n\nRESULTS\n teamed up to find some food'], ['test2' , 'anthropolo
我有下面的DataFrame
pred[['right_context', 'PERC']]
Out[247]:
right_context PERC
0 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 0.000197
1 San Pedro xxxxxxxxxxxx 0.572630
2 zxxxxxxxxxxxxxxxxxxxxxxxxxxx 0.572630
3 de San Pedro
我有一个标准的熊猫DataFrame由字符串组成的句子(如下图所示),我想显示在‘身体’的任何地方都有单词“世界”的行。df.isin(['world'])不能工作,因为它只匹配精确的标签。如果"world“一词出现在'body‘文本中的任何地方,我想返回True。
body
0 'Hello world hi hi'
1 'My name is David, hello'
2 ...
我尝试过的代码是:
df.isin(['world'])
它产生:
body
0 False
1 False
2 ...