[Text_Mining]notes_1

Text2 = text1.split(‘  ‘ )

[w for w in text2 if w.endswith(‘s’)]

Find unique words :  set(text4)  set([w.lower() for w in text4])

S.startswith(t)

S.endswith(t)

T in s

S.isupper(); s.islower(); s.istitle()

S.isalpha(); s.isdigit(); s.isalnum()

S.lower(); s.upper(); s.titlecase()

S.split(t); s.splitlines()

S.join(t)

S.strip(); s.rstrip()

S.find(t); s.rfind(t)

S.replace(u,v)

 

File operation

F = open(filename,mode)

F.readline(); f.read(); f.read(n)

For lline in f: do something(line)

F.seek(0) reset the reading pointer

F.write(message)

F.close()

How do you remove the last newline character?

Text14.rstrip()

 

Finding specific words

Hashtags

[w for w in text11 if w.startswith(‘#’)]

Callouts

[w for w in text11 if w.startswith(‘@’)]

 

Import regular expression first

>>>Import re

>>>[w for w in text11 if re.search(‘@[A-Za-z0-9]+’,w)

>>>[‘@UN’ , ’@UN_Women’]

Means:

Starts with @

Followed by any alphabet(upper or lower case),digit, or underscore that repeats at least once,but any number of times.

 

Text12 = ‘ouagadougou’

re.findall(r’[aeiou]’, text12)  find all vowel

Re.findall(r’[^aeiou]’, text12)  find out everything that is not a vowel

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值