简体   繁体   English

预处理 python 中的文本数据

[英]Preprocessing text data in python

There is a text file(a.text) such as the below example.有一个文本文件(a.text),如下例所示。 For each data, I want to add some features like password length, number of uppercase letters, number of lowercase) and rename each file.对于每个数据,我想添加一些功能,如密码长度、大写字母数量、小写字母数量)并重命名每个文件。 How to coding in python?如何在 python 中编码?

(example) before (例)之前

!2QqWwee

!Hihellohi!

1111111

12345678

(example) after (示例)之后

!2QqWwee, 8, 2, 4

!Hihellohi!, 11, 1, 8

11111111, 8, 0, 0

12345678, 8, 0, 0

You want this?你要这个?

def UpperLower(each_password):
    CounterDict = {"UpperCount": 0, "LowerCount": 0}
    for each_character in each_password:
        if each_character.isupper():
           CounterDict["UpperCount"] += 1
        elif each_character.islower():
           CounterDict["LowerCount"] += 1
        else:
           pass
    print(each_password, len(each_password), CounterDict["UpperCount"], CounterDict["LowerCount"])

Passwords = ["!2QqWwee", "!Hihellohi!", "11111111", "12345678"]

for each_password in Passwords:
    UpperLower(each_password)

Results:结果:

# !2QqWwee 8 2 4
# !Hihellohi! 11 1 8
# 11111111 8 0 0
# 12345678 8 0 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM