Skip to main content
deleted 5 characters in body
Source Link

objects. The advantage is that the file is properly closed after its suite finishes, even if an exception is raised at some point.

  • Use simple str.split instead of regex r'([A-z]+?-\d{4})': row['Date'].split('-').

  • You can pass qotechar="'" to csv.DictReader and then you won't have to strip them manually.

  • To append an item at the end use list.append instead of vlist.insert(len(list), item).

  • The for-loop in agg_dict_to_lists can be reduced to:

      for key, values in agg_dict.iteritems():
          values_list = list(key) + [sum(values), len(values)]
          summary_list.append(values_list) 
    
  • If you're expecting currency to be decimal then use decimal module instead of plain floats. Decimals objects provides better floating-point arithmetic and alterable precision.

  • The format() is not required here: datetime.today().strftime("{0}{1}{2}".format("%y", "%m", "%d")). You could simply do: datetime.today().strftime('%y%m%d').

  • If you're opening the file in binary mode open(output_csv, 'wb') the make sure you're converting the data being written to bytes first by encoding individual items of the rows. This would otherwise not even work in Python 3 where you cannot mix bytes and str anymore.

  • print is not a function in Python 2 unless your import it using from __future__ import print_function. Hence, don't use it with parenthesis.

objects. The advantage is that the file is properly closed after its suite finishes, even if an exception is raised at some point.

  • Use simple str.split instead of regex r'([A-z]+?-\d{4})': row['Date'].split('-').

  • You can pass qotechar="'" to csv.DictReader and then you won't have to strip them manually.

  • To append an item at the end use list.append instead of vlist.insert(len(list), item).

  • The for-loop in agg_dict_to_lists can be reduced to:

      for key, values in agg_dict.iteritems():
          values_list = list(key) + [sum(values), len(values)]
          summary_list.append(values_list) 
    
  • If you're expecting currency to be decimal then use decimal module instead of plain floats. Decimals objects provides better floating-point arithmetic and alterable precision.

  • The format() is not required here: datetime.today().strftime("{0}{1}{2}".format("%y", "%m", "%d")). You could simply do: datetime.today().strftime('%y%m%d').

  • If you're opening the file in binary mode open(output_csv, 'wb') the make sure you're converting the data being written to bytes first by encoding individual items of the rows. This would otherwise not even work in Python 3 where you cannot mix bytes and str anymore.

objects. The advantage is that the file is properly closed after its suite finishes, even if an exception is raised at some point.

  • Use simple str.split instead of regex r'([A-z]+?-\d{4})': row['Date'].split('-').

  • You can pass qotechar="'" to csv.DictReader and then you won't have to strip them manually.

  • To append an item at the end use list.append instead of vlist.insert(len(list), item).

  • The for-loop in agg_dict_to_lists can be reduced to:

      for key, values in agg_dict.iteritems():
          values_list = list(key) + [sum(values), len(values)]
          summary_list.append(values_list) 
    
  • If you're expecting currency to be decimal then use decimal module instead of plain floats. Decimals objects provides better floating-point arithmetic and alterable precision.

  • The format() is not required here: datetime.today().strftime("{0}{1}{2}".format("%y", "%m", "%d")). You could simply do: datetime.today().strftime('%y%m%d').

  • If you're opening the file in binary mode open(output_csv, 'wb') the make sure you're converting the data being written to bytes first by encoding individual items of the rows. This would otherwise not even work in Python 3 where you cannot mix bytes and str anymore.

  • print is not a function in Python 2 unless your import it using from __future__ import print_function. Hence, don't use it with parenthesis.

added 272 characters in body
Source Link

objects. The advantage is that the file is properly closed after its suite finishes, even if an exception is raised at some point.

  • Use simple str.split instead of regex r'([A-z]+?-\d{4})': row['Date'].split('-').

  • You can pass qotechar="'" to csv.DictReader and then you won't have to strip them manually.

  • To append an item at the end use list.append instead of vlist.insert(len(list), item).

  • The for-loop in agg_dict_to_lists can be reduced to:

      for key, values in agg_dict.iteritems():
          values_list = list(key) + [sum(values), len(values)]
          summary_list.append(values_list) 
    
  • If you're expecting currency to be decimal then use decimal module instead of plain floats. Decimals objects provides better floating-point arithmetic and alterable precision.

  • The format() is not required here: datetime.today().strftime("{0}{1}{2}".format("%y", "%m", "%d")). You could simply do: datetime.today().strftime('%y%m%d').

  • If you're opening the file in binary mode open(output_csv, 'wb') the make sure you're converting the data being written to bytes first by encoding individual items of the rows. This would otherwise not even work in Python 3 where you cannot mix bytes and str anymore.

objects. The advantage is that the file is properly closed after its suite finishes, even if an exception is raised at some point.

  • Use simple str.split instead of regex r'([A-z]+?-\d{4})': row['Date'].split('-').

  • You can pass qotechar="'" to csv.DictReader and then you won't have to strip them manually.

  • To append an item at the end use list.append instead of vlist.insert(len(list), item).

  • The for-loop in agg_dict_to_lists can be reduced to:

      for key, values in agg_dict.iteritems():
          values_list = list(key) + [sum(values), len(values)]
          summary_list.append(values_list) 
    
  • If you're expecting currency to be decimal then use decimal module instead of plain floats. Decimals objects provides better floating-point arithmetic and alterable precision.

  • The format() is not required here: datetime.today().strftime("{0}{1}{2}".format("%y", "%m", "%d")). You could simply do: datetime.today().strftime('%y%m%d').

  • If you're opening the file in binary mode open(output_csv, 'wb') the make sure you're converting the data being written to bytes first by encoding individual items of the rows.

objects. The advantage is that the file is properly closed after its suite finishes, even if an exception is raised at some point.

  • Use simple str.split instead of regex r'([A-z]+?-\d{4})': row['Date'].split('-').

  • You can pass qotechar="'" to csv.DictReader and then you won't have to strip them manually.

  • To append an item at the end use list.append instead of vlist.insert(len(list), item).

  • The for-loop in agg_dict_to_lists can be reduced to:

      for key, values in agg_dict.iteritems():
          values_list = list(key) + [sum(values), len(values)]
          summary_list.append(values_list) 
    
  • If you're expecting currency to be decimal then use decimal module instead of plain floats. Decimals objects provides better floating-point arithmetic and alterable precision.

  • The format() is not required here: datetime.today().strftime("{0}{1}{2}".format("%y", "%m", "%d")). You could simply do: datetime.today().strftime('%y%m%d').

  • If you're opening the file in binary mode open(output_csv, 'wb') the make sure you're converting the data being written to bytes first by encoding individual items of the rows. This would otherwise not even work in Python 3 where you cannot mix bytes and str anymore.

Source Link

objects. The advantage is that the file is properly closed after its suite finishes, even if an exception is raised at some point.

  • Use simple str.split instead of regex r'([A-z]+?-\d{4})': row['Date'].split('-').

  • You can pass qotechar="'" to csv.DictReader and then you won't have to strip them manually.

  • To append an item at the end use list.append instead of vlist.insert(len(list), item).

  • The for-loop in agg_dict_to_lists can be reduced to:

      for key, values in agg_dict.iteritems():
          values_list = list(key) + [sum(values), len(values)]
          summary_list.append(values_list) 
    
  • If you're expecting currency to be decimal then use decimal module instead of plain floats. Decimals objects provides better floating-point arithmetic and alterable precision.

  • The format() is not required here: datetime.today().strftime("{0}{1}{2}".format("%y", "%m", "%d")). You could simply do: datetime.today().strftime('%y%m%d').

  • If you're opening the file in binary mode open(output_csv, 'wb') the make sure you're converting the data being written to bytes first by encoding individual items of the rows.