python if else用法筛选出成绩不及格的学生的姓名_在excel Python中筛选列

我并不是真的使用Python来实现这一点,但这里有一个比较简单的方法,我很快就找到了。import openpyxl

wb = openpyxl.load_workbook('test.xlsx')

ws1 = wb.active

toSbN.pngnames = []

for row in ws1.columns[0]:

names.append(row.value)

names = sorted(list(set(names)))

start = 1

for name in names:

ws1.cell(row = start, column=2).value = name

start += 1

wb.save('test.xlsx')

pfwWS.png

编辑:显然更新的openpyxl需要稍作修改

更改此:for row in ws1.columns[0]:

names.append(row.value)

对此:for row in ws1.iter_cols(max_col = 1, min_row=1):

for cell in row:

names.append(cell.value)

万一你的专栏不一样iter_cols(min_col=None, max_col=None, min_row=None, max_row=None)[source]

Returns all cells in the worksheet from the first row as columns.

If no boundaries are passed in the cells will start at A1.

If no cells are in the worksheet an empty tuple will be returned.

Parameters:

min_col (int) – smallest column index (1-based index)

min_row (int) – smallest row index (1-based index)

max_col (int) – largest column index (1-based index)

max_row (int) – smallest row index (1-based index)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值