python简单的数据处理(文件)

1.数据分割


CSDNfilepath=r"这里填要处理的文件路径"
CSDNpasswordpath=r"这里自定义截取密码后的路径\截取密码.txt"
CSDNreadfile=open(CSDNfilepath,"r",errors="ignore")
CSDNpasswordfile=open(CSDNpasswordpath,"w")
while True:
    line = CSDNreadfile.readline()
    if not line:
        break
    csdnList = line.split(" # ")
    CSDNpasswordfile.write(csdnList[1]+"\n")

CSDNreadfile.close()
CSDNpasswordfile.close()

2.数据排序

对截取的密码数据进行排序,以便后边查重

CSDNfilepath=r"这里是截取好密码的路径\截取密码.txt"
CSDNpasswordpath=r"这里自定义对密码排序后要保存的路径\密码排序1.txt"
CSDNreadfile=open(CSDNfilepath,"r",errors="ignore")
CSDNpasswordfile=open(CSDNpasswordpath,"w")

csdnList = CSDNreadfile.readlines()
csdnList.sort()

for pwd in csdnList:
    CSDNpasswordfile.write(pwd)
CSDNreadfile.close()
CSDNpasswordfile.close()

3.分析密码出现次数

CSDNfilepath=r"这里是对密码排序后的路径\密码排序1.txt"
CSDNpasswordpath=r"这里自定义对密码判断出现次数的路径\判断出现次数.txt"
CSDNreadfile=open(CSDNfilepath,"r",errors="ignore")
CSDNpasswordfile=open(CSDNpasswordpath,"w")

csdnList = CSDNreadfile.readlines()
pwdLength = len(csdnList)

i = 0
while i < pwdLength:
    times = 1
    while i+1 <= pwdLength-1 and csdnList[i] == csdnList[i+1]:
        times += 1
        i += 1
    CSDNpasswordfile.write(str(times)+" # "+csdnList[i])
    i += 1

CSDNreadfile.close()
CSDNpasswordfile.close()

4.根据次数进行排序

CSDNfilepath=r"这里是对密码判断出现次数的路径\判断出现次数.txt"
CSDNpasswordpath=r"这里自定义对密码判断出现次数排序的路径\出现次数排序.txt"
CSDNreadfile=open(CSDNfilepath,"r",errors="ignore")
CSDNpasswordfile=open(CSDNpasswordpath,"w")

newList = []
csdnList = CSDNreadfile.readlines()
for line in csdnList:
    lineList = line.split(" # ")
    newLineList = [eval(lineList[0]),lineList[1]]
    newList.append(newLineList)

newList.sort(key=lambda x:x[0])
newList.reverse()

for pwd in newList:
    CSDNpasswordfile.write(str(pwd[0]) + "," + pwd[1])

CSDNreadfile.close()
CSDNpasswordfile.close()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值