假设我有一个数据帧,比如
Group Score
Duck QuackDUC 0.343
Ten TopTEN 0.198
** -Men MaleMEN 0.350
y -Rural AreaRU 0.888
Maple TreeMAP 0.468
Man NavyMN 0.150
我想提取每个Group中的单词,它是空格‘’之后的字符串,在2-3个字符字符串之前,全部大写。也就是说,我希望结果是
Group Score
Quack 0.343
Top 0.198
Male 0.350
Area 0.888
Tree 0
我有一个包含单词嵌入的pandas数据帧。单词是列名。为了得到句子的最终嵌入,我这样做:
st = ['some','random','text']
a = df[st].sum(axis=1)
当所有术语都出现在数据帧中时,这种方法效果很好。但是,当数据帧中不存在该列时,它会引发一个键错误。目前,我对每一项都进行了循环,并进行了try操作。我想避免循环,在一行中做事情。熊猫有没有提供同样的选择。
我的问题基本上是这样的。我有一个pandas dataframe,它的一个列包含相当多的文本(通常是20到200个单词)。这个数据帧大约有600k行。最重要的是,我有一个单词列表,大约有15万个条目长,需要从数据帧中的字符串中过滤掉。我目前正在使用这个方法来做这件事:
for word in uncommon_words:
reports['Report_Clean_Filtered'] = reports['Report_Clean'].str.replace(word, '')
其中uncommon_words是单词列表,报告是数据帧
提取到数据框中的API数据在几个注释单元格中包含空值。我最终希望将数据帧加载到csv文件中。当我将数据帧加载到csv时,注释中的空行被视为新行,因此在csv中给出了错误的行数。
数据帧:
Employee_id | Employeee_comments
---------------------------------------
1 | 1. This is test comment 1
| 2. This is test comment 2
|
| Comments above employee a
我有一个像这样的文本,Cat In A Tea Cup by New Yorker cover artist Gurbuz Dogan Eksioglu,Handsome cello wrapped hard magnet, Ideal for home or office.我用下面的代码删除了这个文本中的标点符号。 import string
string.punctuation
def remove_punctuation(text):
punctuationfree="".join([i for i in text if i not in string.punc
我有一个包含文本数据的dataframe列。它很少有重复字母的单词。我希望找到所有这样的单词,然后将这些单词作为键存储在字典中,并将它们的正确拼写作为值存储在字典中,然后用字典中的值替换数据帧中的单词。例如,如果我的dataframe有这样的词- id text
1 Hiiiiiii
2 Good morninggggggg
3 See you soooonnnn 1)我需要在dataframe列中找到这些单词2)将这些单词存储在字典中{Hiiiiiii : Hi,morninggggggg : words,soooonnnn :soooonnnn} 3)然后将数
R的新知识。我希望从数据帧中删除某些单词。因为有多个单词,所以我想将这个单词列表定义为一个字符串,并使用gsub删除。然后转换回数据帧并保持相同的结构。
wordstoremove <- c("ai", "computing", "ulitzer", "ibm", "privacy", "cognitive")
a
id text time username
1 "ai and x" 10
我有一个示例数据帧文本列,其中包含字符串,包括单词'eng‘和单词'engine’。
ID Text
1 eng is here
2 engine needs washing
3 eng is overheating
我想把'eng‘改为'engine’。我使用以下代码:
df['Text'] = df['Text'].str.replace('eng', 'engine')
但这把我第二排的短信搞砸了。第二行变成
ID Text
2 engineine needs washi
我有两个数据帧A和B。我想检查数据帧A的唯一单词是否存在于dataframe B中。如果存在,则保留该单词,否则从每一行dataframe B中删除单词。
A <- data.frame(name = c(
"X-ray right leg arteries",
"consultation of gynecologist",
"x-ray leg arteries",
"x-ray leg with 20km distance"
), stringsAsFactors = F)
B <- data.f
我有一个单词列表,如下所示 list_example['one', 'two', 'three', 'four'] 以及与其他词一致的数据帧,例如: col1, col2, col3
0 two nine ten
1 two three ten
2 five NaN NaN
2 five three NaN
2 two NaN NaN
2 five NaN NaN
2 two NaN NaN
2 five NaN
我有一个句子列表,我需要用数据帧列中的一个单词替换每个单词。这是一对一的通信。这是我的密码:
def replace_words(x):
z = [word for line in x for word in line.split()]
for i in range(0 ,(len(z)-1)):
z[i] = str.replace(z[i],dataframe[i])
return z
这最终会产生一个错误“不能赋值给函数调用”。数据是这样的:
x = ['I love flappy brd' , 'i got a platium m
我有两个数据帧
(1st Dataframe)
**Sentences**
hello world
live in the world
haystack in the needle
(2nd Dataframe in descending order by Weight)
**Words** **Weight**
world 80
hello 60
haystack 40
needle 20
我想要检查第一个数据帧中的每个句子,如果句子中的任何单词包含第二个数据帧中列出的单词,并选择具有最高权重数字的单词。然后,我将把找到
我有两个数据帧,如下: DF1:
Name Value
buying fish hook 240
arrange lunch 75
repair equipment 800
purchase air condition 1400
buying fish 66
DF 2:
Name
fish
lunch
equipemt
air condition
hair condition
fish hook
我想用模糊逻辑匹配来自两个数据帧的名称列中的名称,并将第二个数据帧中的名称列
我有两个数据帧,看起来像这样(尽管第一个数据帧有9000多万行,第二个数据帧有1400多万行),第二个数据帧也是随机排序的
df1 <- data.frame(
datalist = c("wiki/anarchist_schools_of_thought can differ fundamentally supporting anything from extreme wiki/individualism to complete wiki/collectivism",
"strains of anarchism have oft
我有一个庞大的数据框架,我导出为一个excel文件,通过删除重复项并创建一个列并更正所有单词来修复拼写。现在,我想重新导入校正后的数据,用新值替换旧值,这样在数据框架中,‘become’的每个实例都会变成'New York‘。此处,位置是数据帧中的值,最终位置是excel中编辑的位置。
Location Final Location
New Yo New York
Austin Austin
Londn London
Pais Paris
Berlin Berlin
Mosscow Moscow
Varsaw Warsaw
任何帮助都将不胜感激。
我正在尝试分解数据帧的文本列,并按行/文档分解前几个单词。我有最热门的单词,在这个例子中,机器和学习都是8。但是我不确定如何分解每个文档的最高单词,而不是整个数据帧。 下面是整个数据框中最热门的单词的结果: 机器8 学习8 重要2 思考1 重要的1 import pandas as pd
y = ['machine learning. i think machine learning rather significant machine learning',
'most important aspect is machine learning. machin
我想从次要数据帧中删除主数据帧中的单词。
这是主要的数据框架:
+----------+--------------------+
| event_dt| cust_text|
+----------+--------------------+
|2020-09-02|hi fine i want to go|
|2020-09-02|i need a line hold |
|2020-09-02|i have the 60 packs|
|2020-09-02|hello want you teach|
下面是单列辅助数据帧.在第二数据帧中的单词需要从列cust_
我想检查一个数据帧B行中的单词是否存在于另一个数据帧A行中,并检索数据帧A的LineNumber。
数据帧A示例
LineNumber Description
2539 5401845 Either the well was very deep, or she fell very slowly,
4546 5409117 for she had plenty of time as she went down to look about her,
4368 5408517 and to wonder what was going to hap
我有一个字符串,包含单词、空格和数字(整数和小数)。我希望将它们分隔为数据帧中的两列,以便列A包含文本,列B包含数字。这似乎是一个超级简单的任务,但我不知道如何捕捉文本。不过,我确实记录了这些数字。
require(tidyr)
df <- data.frame(x = c("This is text0", "This is a bit more text 0.01", "Even more text12.231"))
捕获了B列中的数字,但我不知道如何在第一组括号中插入什么regex以获得A中的文本
df |>
extract