python 判定数据是否为递增

##背景:需要判定excel文件的某一列是否为递增,如果是的话,还需要修正
xl_r = xlrd.open_workbook("xxx.xls")
# 打开文件并赋值给一个变量
xls_r_sheet = xl_r.sheet_by_index(0)
# 获取第一个sheet表中所有数据
xls_r_col_datas = xls_r_sheet.col_values(2)
# 获取第三列所有数据
new_list = xls_r_col_datas.copy()
# 不能直接使用=,否则指向同一个内存
same_start_index = 0
# 有递增就保持当前相同的第一位
compare_index = 1
# 用于两两比较
for list_index in range(1, len(xls_r_col_datas)):
	first_str  = xls_r_col_datas[same_start_index]
	second_str = xls_r_col_datas[list_index]
	if first_str   != '' and second_str != '' and (first_str  [:-1] == second_str[:-1]) and (first_str[-1]).isdigit() and second_str[-1].isdigit():
	# 判定不为空,且只有最后一位才不同,并且最后一位是数字
		if int(first_str[-1]) + compare_index = int(second_str[-1]):
			print("是递增 %s %s" %(first_str,second_str))
			new_list[list_index] = first_str
			compare_index = compare_index + 1
	#elif first_str   !=
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值