社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

TomNash

TomNash 最近创建的主题
TomNash 最近回复了

使用正则表达式提取不同的组并根据需要重新排序。

import re
new_lines = []
with open('inputdata.txt', 'r') as file:
    for line in file:
        regex = re.compile(r'(\w+),\s?(Mr.|Miss.|Mrs.)\s(\w+\s?\w*\s),([01])')
        new_line = regex.findall(line)[0]
        print(f"{new_line[0]},{new_line[2]},{new_line[3]},{new_line[1]}")

结果:

Braund,Owen Harris ,1,Mr.
Heikkinen,Laina ,0,Miss.
Allen,William Henry ,0,Mr.

这在纽比到 base_repr() :

import numpy as np
[np.base_repr(100, base) for base in range(2,11)]

结果:

['1100100', '10201', '1210', '400', '244', '202', '144', '121', '100']