<tfoot id='8fLEE'></tfoot>
    1. <i id='8fLEE'><tr id='8fLEE'><dt id='8fLEE'><q id='8fLEE'><span id='8fLEE'><b id='8fLEE'><form id='8fLEE'><ins id='8fLEE'></ins><ul id='8fLEE'></ul><sub id='8fLEE'></sub></form><legend id='8fLEE'></legend><bdo id='8fLEE'><pre id='8fLEE'><center id='8fLEE'></center></pre></bdo></b><th id='8fLEE'></th></span></q></dt></tr></i><div id='8fLEE'><tfoot id='8fLEE'></tfoot><dl id='8fLEE'><fieldset id='8fLEE'></fieldset></dl></div>
      <legend id='8fLEE'><style id='8fLEE'><dir id='8fLEE'><q id='8fLEE'></q></dir></style></legend>

        • <bdo id='8fLEE'></bdo><ul id='8fLEE'></ul>

        <small id='8fLEE'></small><noframes id='8fLEE'>

      1. Python 的 CSV 阅读器和迭代

        Python#39;s CSV reader and iteration(Python 的 CSV 阅读器和迭代)
      2. <small id='2BL7e'></small><noframes id='2BL7e'>

          <tbody id='2BL7e'></tbody>
          <bdo id='2BL7e'></bdo><ul id='2BL7e'></ul>
          <i id='2BL7e'><tr id='2BL7e'><dt id='2BL7e'><q id='2BL7e'><span id='2BL7e'><b id='2BL7e'><form id='2BL7e'><ins id='2BL7e'></ins><ul id='2BL7e'></ul><sub id='2BL7e'></sub></form><legend id='2BL7e'></legend><bdo id='2BL7e'><pre id='2BL7e'><center id='2BL7e'></center></pre></bdo></b><th id='2BL7e'></th></span></q></dt></tr></i><div id='2BL7e'><tfoot id='2BL7e'></tfoot><dl id='2BL7e'><fieldset id='2BL7e'></fieldset></dl></div>
        • <tfoot id='2BL7e'></tfoot>
              1. <legend id='2BL7e'><style id='2BL7e'><dir id='2BL7e'><q id='2BL7e'></q></dir></style></legend>

                  本文介绍了Python 的 CSV 阅读器和迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I have a CSV file that looks like this:

                  "Company, Inc.",,,,,,,,,,,,10/30/09
                  A/R Summary Aged Analysis Report,,,,,,,,,,,,10:35:01
                  All Clients,,,,,,,,,,,,USER
                  
                  Client Account,Customer Name,15-Jan,16 - 30,31 - 60,61 - 90,91 - 120,120 - Over,Total,Status,Credit Limit
                  1000001111,CLIENT A,0,0,"3,711.32",0,0,"18,629.64","22,340.96",COD,"20,000.00"
                  1000002222,CLIENT B,0,0,0,"3,591.27",0,0,"3,591.27",COD,0
                  1000003333,CLIENT C,536.78,0,0,0,0,"11,216.60","11,753.38",COD,0
                  1000004444,CLIENT D,0,514.94,"3,147.45",690,0,0,"4,352.39",COD,0
                  
                  Grand Total,,"139,203,856.06","84,607,749.30","110,746,640.18","58,474,379.45","52,025,869.06","292,653,734.82","737,712,228.87",,,,
                  

                  But I only want to process the lines after the line "Client Account..." and before "Grand Total..." Here's the code that I'm using now:

                  inputFile = csv.reader(open(filename), dialect='excel')
                  records = [line for line in inputFile if line and line[0].isdigit()]
                  

                  解决方案

                  Via generators. You can build all kinds of complexity from simple generator-filter functions. While considerably more complex than your filter, this is more extensible and can easily handle really complex spreadsheets.

                  def skip_blank( rdr ):
                      for row in rdr:
                          if len(row) == 0: continue
                          if all(len(col)==0 for col in row): continue
                          yield row
                  
                  def after_heading( text, rdr ):
                      i= iter(rdr)
                      for row in i:
                          if any( column == text for column in row ):
                              break
                      for row in i:
                          yield row
                  
                  def before_footing( text, rdr ):
                      for row in rdr:
                          if any( column == text for column in row ):
                              break
                          yield row
                  
                  def between( start, end, rdr ):
                      for row in before_footing( end, after_heading( start, rdr ) ):
                          yield row
                  
                  for row in between( 'Grand Total', 'Client Account', skip_blank( inputFile ) ):
                      print row
                  

                  这篇关于Python 的 CSV 阅读器和迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Running .jl file from R or Python(从 R 或 Python 运行 .jl 文件)
                  Running Julia .jl file in python(在 python 中运行 Julia .jl 文件)
                  Using PIP in a Azure WebApp(在 Azure WebApp 中使用 PIP)
                  How to run python3.7 based flask web api on azure(如何在 azure 上运行基于 python3.7 的烧瓶 web api)
                  Azure Python Web App Internal Server Error(Azure Python Web 应用程序内部服务器错误)
                  Run python dlib library on azure app service(在 azure app 服务上运行 python dlib 库)

                    • <tfoot id='tuY5Y'></tfoot>

                    • <legend id='tuY5Y'><style id='tuY5Y'><dir id='tuY5Y'><q id='tuY5Y'></q></dir></style></legend>

                        <i id='tuY5Y'><tr id='tuY5Y'><dt id='tuY5Y'><q id='tuY5Y'><span id='tuY5Y'><b id='tuY5Y'><form id='tuY5Y'><ins id='tuY5Y'></ins><ul id='tuY5Y'></ul><sub id='tuY5Y'></sub></form><legend id='tuY5Y'></legend><bdo id='tuY5Y'><pre id='tuY5Y'><center id='tuY5Y'></center></pre></bdo></b><th id='tuY5Y'></th></span></q></dt></tr></i><div id='tuY5Y'><tfoot id='tuY5Y'></tfoot><dl id='tuY5Y'><fieldset id='tuY5Y'></fieldset></dl></div>

                          <small id='tuY5Y'></small><noframes id='tuY5Y'>

                            <tbody id='tuY5Y'></tbody>

                          • <bdo id='tuY5Y'></bdo><ul id='tuY5Y'></ul>