dataframe列包含几个没有意义的三个和两个字母单词的句子。我希望在dataframe列中找到所有这样的单词,然后从dataframe列中删除它们。df-
id text
1 happy birthday syz
2 vz
3 have a good bne weekend
我希望1)找到长度小于3的所有单词。(这将返回syz,vz,bne) 2)删除这些单词(注意,停止词已经被移除,所以像"a“、”现在在dataframe列中不存在了,上面的dataframe只是一个例子)。“
我尝试了下面的代码,但它不起作用
def word_l
我想写一个.csv文件。其中一列是“单词”。每个类别的单词都排在一起,单元格“word”有一个单词列表,我将其读为:
words = []
for i in range(len(category)):
r = requests.post(base_url+'/'+url[i])
if r.ok:
data = r.content.decode('utf8')
words.append(pd.Series.tolist((pd.read_csv(io.StringIO(data), squeeze=True))
我有一个Pandas DataFrame,它是通过读取带有表格的PDF表格创建的。PDF的解析并不完美,因此我最后在结果的DataFrame中将几个表列擦成了一个列。问题是PDF中的表列之一是文本,因此有时有一个词,有时有两个单词组成该列。示例:
Col_1 Col_2
0 Hello X Y A
1 Hello world Q R B
2 Hi S T C
我想将Col_1分成3列。我不知道如何做到这一点,因为第一列有时由一个单词组成,如行0& 2,有时由两个单词组成,如第1行。
我尝试过用Col_
我试图将只包含字母的单词提取到新的列中,任何包含数字的单词都提取到不同的列中。
期望输出:
query words_only contains_number
0 Nike Air Max 97 Nike Air Max 97
1 Adidas NMD-R1 Adidas NMD-R1
2 Nike Air Max 270 Nike Air Max 270
我尝试过的:
我在这里看到了一些答案,但这并不完全是我所需要的。
最小可重现性示例:
# Import p
我尝试在两个dataframe列之间查找字符串之前和之后的前三个单词,并在名为“words after”和“Words after”的两个新列中返回。 我的数据帧 Keyword Description
pet cat car dog pet day bye are 我想要的输出 Keyword Description Words Before Words After
pet cat car dog pet day bye are
我有两个列的dataframe和一个单词列表。我希望通过这个列表过滤数据的一个列,并将该列的匹配行保存到一个新列表中,同时从另一个列中获取相同索引的值,以便将该值保存在第二个列表中。
所以我基本上想用一列过滤我的数据,除了我有字符串,我想要和单词进行比较,所以我必须遍历它们。
我的代码:
dataframe:
letter | sentence
----------------------------------------
L | "Lorem ipsum dolor sit amet"
C | "consectetur adipiscing el
我有一个dataframe,它在一列中包含句子、我从该列中提取的特定单词,第三列包含第二列中单词的同义词列表:
data= {"sentences":["I am a student", "she is my friend", "that is the new window"],
"words": ["student","friend", "window"],
"synonyms":[["pupil"],[&
我正在尝试在我的dataframe (Title)的某一列中查找部分字符串匹配。理想情况下,如果部分字符串匹配为true,我希望pandas创建一个true false列,如果字符串匹配为false,则创建false列。我想给你一个def函数,以便创建一个if/else语句,因为我的数据集非常大。
如果“Title”列中有单词“dog”,那么在我的新列“Match”中的该行中放一个true。
Old Dataframe example:
Title Author Name
Dogs R Us John Smith
Pigs can Fly Henry Wh
如果我有以下列的dataframe:
df$text <- c("This string is not that long", "This string is a bit longer but still not that long", "This one just helps with the example")
像这样的字符串:
keywords <- c("not that long", "This string", "example", "helps")
我正在尝
我有一个包含两列Stg和Txt的数据框。任务是用每个Txt行检查Stg列中的所有单词,并将匹配的单词输出到新列中,同时保持单词的大小写与Txt中的大小写相同。 Example Code:
from pandas import DataFrame
new = {'Stg': ['way','Early','phone','allowed','type','brand name'],
'Txt': ['An early term',&
我需要在R中的一个2列数据框中找到列1中行中某些字符之间的所有字符串,然后我需要将它们放入一个新的表或数据框中,该表或数据框中的实例在列1中具有与原始数据框中与列1相邻的原始数据框中相同的列2值。我需要获取dataframe foo.df第1列中xx...xx之间的所有单词,并将它们放入一个包含第2列的新表中,该表显示了foo.df中相应行中的用户: 我们可以这样制作数据帧: text <- c('hello xxthisxx is a xxtestxx of','we xxarexx very happy','you will xxwantxx
我有一个有3列的dataframe:'text', 'in', 'tar' of type(str, list, list)。
text in tar
0 This is an example text that I use in order to ... [2] [6]
1 Discussion: We are examining the possibility of ... [
我有一个专栏,我试图通过删除一个特定单词之前的所有单词来清理。
data = ['The text is interesting but short' ,'The text is interesting but short' ,'The text is interesting but short' ,'The text is interesting but short' ,'The text is interesting but short' ,'The text is interesting but sh
我在r中有一个单词的向量。
words = c("Awesome","Loss","Good","Bad")
并且,我在r中有以下数据
ID Response
1 Today is an awesome day
2 Yesterday was a bad day,but today it is good
3 I have losses today
我想要做的是,在响应列中匹配的单词应该被提取出来并插入到dataframe的新列中。最终输出应该如下
我在一个dataframe中有两个字符串列,我希望从A中减去B中常见的单词。
A -> Stack Overlflow is great
B -> stack great
A-B -> overflow is
我试过以下代码。但它只有在B列只有一个词的情况下才能起作用。
df['A-B'] = [' '.join(set(a.split())-set(b.split())) for a, b in zip(df['A'], df['B'])]
当B有多个单词时,我能做什么改变使它
我正在尝试使用regex来删除或替换dataframe中字符串列中特定单词后面的单词。这意味着我不想把这些空格替换掉。只是这个词指的是特定的单词
import pandas as pd
df = pd.DataFrame({'STRING': [r"THERE IS NO REASON WHY THIS SHOULDN'T WORK!", r"I AM WITHOUT DOUBT VERY BAD AT REGEX", r"I CAN'T SOLVE A PROBLEM HAT HAS NO INTRINSIC