Python删除excel电子表格中的一行 [英] Python to delete a row in excel spreadsheet

查看:1790
本文介绍了Python删除excel电子表格中的一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常大的ex​​cel文件,我需要删除约20,000行,这取决于符合一个简单的条件,而excel不会让我删除这样一个复杂的范围,当使用过滤器。条件是:



如果第一列包含值X,那么我需要删除整行。



我试图使用python和xlwt自动化,但不太确定从哪里开始。寻求一些代码片段让我开始...
感谢任何帮助,在那里!

解决方案

Don'删除。只需复制你需要的东西。


  1. 阅读原始文件

  2. 打开一个新文件

  3. 迭代原始文件的行(如果行的第一列不包含值X,将此行添加到新文件)

  4. close两个文件

  5. 将新文件重命名为原始文件


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.

  1. read the original file
  2. open a new file
  3. 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)
  4. close both files
  5. rename the new file into the original file

这篇关于Python删除excel电子表格中的一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆