<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 阅读器和迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                  Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)

                    • <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>