python删除excel某行的格式,Python删除excel电子表格中的一行

针对一个大型Excel文件,需要删除20,000行含有特定值X的第一列的行。博主尝试用Python和xlwt库自动化这一过程,但不知从何开始。建议的解决方案是不直接删除,而是读取原始文件,创建新文件,只将不包含X值的行写入新文件,最后重命名新文件为原始文件。
摘要由CSDN通过智能技术生成

I have a really large excel file and i need to delete about 20,000 rows, contingent on meeting a simple condition and excel won't let me delete such a complex range when using a filter. The condition is:

If the first column contains the value, X, then I need to be able to delete the entire row.

I'm trying to automate this using python and xlwt, but am not quite sure where to start. Seeking some code snippits to get me started...

Grateful for any help that's out there!

解决方案

Don't delete. Just copy what you need.

read the original file

open a new file

iterate over rows of the original file (if the first column of the row does not contain the value X, add this row to the new file)

close both files

rename the new file into the original file

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值