小编eli*_*isa的帖子

如何提取特定单词之后的行?

我想在python 3中使用正则表达式获取日期和文本中的特定项目。下面是一个示例:

text = '''
190219 7:05:30 line1 fail
               line1 this is the 1st fail
               line2 fail
               line2 this is the 2nd fail
               line3 success 
               line3 this is the 1st success process
               line3 this process need 3sec
200219 9:10:10 line1 fail
               line1 this is the 1st fail
               line2 success 
               line2 this is the 1st success process
               line2 this process need 4sec
               line3 success 
               line3 this is the 2st success process
               line3 this process need 2sec

'''
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,我想获得“成功行”之后的所有行。这里需要输出:

[('190219','7:05:30','line3 this is …
Run Code Online (Sandbox Code Playgroud)

python regex string findall python-3.x

6
推荐指数
1
解决办法
172
查看次数

如何使用Python删除特定单词之前的所有单词(如果有多个特定单词)?

我想删除特定单词之前的所有单词。但我的句子里有一些特定的词。下面的例子:

dvdrentalLOG: statement: SELECT email, actor.last_name, count(actor.last_name) FROM (SELECT email, actor_id FROM (SELECT email, film_id FROM (SELECT email, inventory_id FROM customer as cu JOIN rental ON cu.customer_id = rental.customer_id ORDER BY email) as sq JOIN inventory ON sq.inventory_id = inventory.inventory_id) as sq2 JOIN film_actor ON sq2.film_id = film_actor.film_id) as sq3 JOIN actor ON sq3.actor_id = actor.actor_id GROUP BY email, actor.last_name ORDER BY COUNT(actor.last_name) DESC
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,我想删除第一个SELECT之前的所有单词。我已经尝试过如何删除Python中特定字符之前的所有字符?

知道我需要做什么吗?

python regex postgresql python-3.x

2
推荐指数
1
解决办法
3017
查看次数

如何删除数据框中的引号

我有一个像这样的数据框:

number    file
  1       "[file1,file2]"
  2       [file1]
  3       "[file3,file4]
Run Code Online (Sandbox Code Playgroud)

我想删除". 这是我尝试过的:

 data = df.replace([\"], '', regex=True)
Run Code Online (Sandbox Code Playgroud)

但是,我的数据框中没有任何变化。我该如何解决这个问题?

谢谢。

python dataframe python-3.x pandas

2
推荐指数
1
解决办法
6465
查看次数

标签 统计

python ×3

python-3.x ×3

regex ×2

dataframe ×1

findall ×1

pandas ×1

postgresql ×1

string ×1