正在从excel获取数据。将附加垃圾值。

您好,我正在使用python代码从EXCEL中获取数据..我也能看到它的一些垃圾价值。如[文本:U
如何移除它..以下是代码

选择 | 换行 | 行号
  1. from xlrd import open_workbook
  2. from win32com.client import Dispatch
  3. book = open_workbook('C:/Users/742123/Desktop/test.xls')
  4. sheet0 = book.sheet_by_index(0)
  5. #sheet1 = book.sheet_by_index(1)
  6.  
  7. print sheet0.col(0) 
  8. print sheet0.col(2)
  9. print sheet0.col(3)
  10. print sheet0.col(4)
  11. print sheet0.col(5)
  12. print sheet0.col(6)
  13. print sheet0.col(7)
  14. print sheet0.col(8)
  15. print sheet0.col(9)
  16. print sheet0.col(10)
  17. print sheet0.col(12)
  18. print sheet0.col(13)
  19. print sheet0.col(14)
  20. print sheet0.col(15)
  21. print sheet0.col(16)
  22. print sheet0.col(17)
  23. print sheet0.col(18)
  24. print sheet0.col(19)
  25. print sheet0.col(20)
  26. print sheet0.col(21)
  27. print sheet0.col(22)
  28. print sheet0.col(23)
  29. print sheet0.col(24)
  30. print sheet0.col(25)
  31. print sheet0.col(26)
  32. print sheet0.col(27)
  33.  
# 回答1


我们不知道"垃圾"是什么意思,也不知道它在文件中的位置,所以无法提供任何建议。首先,你必须以某种方式量化你想要和不想要的东西。此外,还可以使用for()循环打印第2列到第27列。

选择 | 换行 | 行号
  1.  for ctr in range(2, 28):
  2.     if 11 != ctr:  ## omit
  3.         print print sheet0.col(ctr) 

标签: python

添加新评论