import re
def convert_status(column):
# iterate over each value in the column
for i in range(len(column)):
# check if the value matches the pattern '0-0000/00/0000' or '0-0000/00/00'
if re.match(r'^\d{1}/[-]\d{4}/\d{2}/\d{2}$', str(column[i])):
#или if re.match(r'^\d+/-/\d+/\d+/\d{2}$', str(column[i])):
# check if the last two digits of the year are '00'
if column[i][-2:] == '00':
# remove the last two digits of the year
column[i] = column[i][:-2]
if re.match(r'^\d{2}/[-]\d{4}/\d{2}/\d{2}$', str(column[i])):
# check if the last two digits of the year are '00'
if column[i][-2:] == '00':
# remove the last two digits of the year
column[i] = column[i][:-2]
if re.match(r'^\d{1}/[-]\d{4}/\d{2}/\d{4}$', str(column[i])):
# check if the last two digits of the year are '00'
if column[i][-4:] == '00' or column[i][-4:-2] == '20':
# remove the last two digits of the year
column[i] = column[i][:-4]
if re.match(r'^\d{2}/[-]\d{4}/\d{2}/\d{4}$', str(column[i])):
# check if the last two digits of the year are '00'
if column[i][-4:] == '00' or column[i][-4:-2] == '20':
# remove the last two digits of the year
column[i] = column[i][:-4]
# check if the value matches the pattern '000000000'
elif re.match(r'ФС № ^\d{9}$', str(column[i])):
# add 'ВС №' prefix to the value
column[i] = column[i][5:]
column[i] = 'ВС № ' + column[i]
elif re.match(r'^\d{9}$', str(column[i])):
# add 'ВС №' prefix to the value
column[i] = 'ВС № ' + column[i]
return column
# convert the 'Статус ИП' column to the desired format
df['Номер ИД'] = df['Номер ИД'].astype(str).apply(convert_status)
df.to_excel('292 отчет.xlsx', index=False)
# print the updated dataframe
print(df['Номер ИД'])
(\d-\d{4}/\d{2,3}/)\d{0,2}(\d{2})
. Пример:import re
r = re.compile(r'(\d-\d{4}/\d{2,3}/)\d{0,2}(\d{2})')
m = r.match("1-2345/678/0099")
print(m.groups()) # выведет ('1-2345/678/', '99')
(\d{9})
import re
r = re.compile(r'(\d{9})')
m = r.match("123456789")
print(m.groups()) # выведет ('123456789', )