鱼C论坛

 找回密码
 立即注册
查看: 2520|回复: 6

提取word文档中某些字符。。

[复制链接]
发表于 2019-11-12 22:13:19 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
str1='Deeper research shows that health statement and other personal information may have nonlinear connections with claim risk. The traditional underwriting process may neglect some important information. The relationship between the health statement and claim risk may be very complex and impossible to be described by a function.
In this paper we proposed a novel algorithm that firstly mines the insured data by association rule [4], [5].'

如果说我想要提取这段字符串里的[4]和[5],该怎么做呢。请教一下各位大佬。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2019-11-12 22:16:19 | 显示全部楼层
首先不可以用re模块哦!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-11-13 07:20:09 From FishC Mobile | 显示全部楼层
qq819343713 发表于 2019-11-12 22:16
首先不可以用re模块哦!

提取文本类,不用re
只能呵呵
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-11-13 09:24:18 | 显示全部楼层
我觉得有时候不要太局限自己的思维吧,最终是要解决问题,用正则或是其他方式,能解决问题就好。

  1. In [66]: str2 = str1[-9:-6]

  2. In [67]: str3 = str1[-4:-1]

  3. In [68]: str2 + ',' + str3
  4. Out[68]: '[4],[5]'
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-11-13 10:39:06 | 显示全部楼层
  1. import string

  2. str2=' ' + '.' + string.ascii_lowercase + '\n'
  3. str1='''Deeper research shows that health statement and other personal information may have nonlinear connections with claim risk. The traditional underwriting process may neglect some important information. The relationship between the health statement and claim risk may be very complex and impossible to be described by a function.
  4. In this paper we proposed a novel algorithm that firstly mines the insured data by association rule [4], [5].'''

  5. str1 = str1.lower()

  6. for i in str2:
  7.     if str1.find(i) != -1:
  8.         str1 = str1.replace(i, '')

  9. print('str1=',str1)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-11-14 03:44:21 | 显示全部楼层

可以的,谢谢了。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-11-14 09:36:51 | 显示全部楼层

请置为最佳
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-1-20 17:06

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表