csv-reader.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #import csv
  2. #with open('sample.csv', newline='') as csvfile:
  3. # samplereader = csv.reader(csvfile, delimiter=',', quotechar='|')
  4. # for row in samplereader:
  5. # print(', '.join(row))
  6. #file = open('sample.csv')
  7. #csv_file = csv.reader(file)
  8. #data = []
  9. #for row in csv_file:
  10. #data.append(row)
  11. #file.close()
  12. #print (data[1:])
  13. #with open('sample.csv', newline='') as f:
  14. # reader = csv.reader(f)
  15. # for row in reader:
  16. # print(row)
  17. #import csv, sys
  18. #filename = 'sample.csv'
  19. #with open(filename, newline='') as f:
  20. # reader = csv.reader(f)
  21. # try:
  22. # for row in reader:
  23. # print(row)
  24. # except csv.Error as e:
  25. # sys.exit('file {}, line {}: {}'.format(filename, reader.line_num, e))
  26. #import csv
  27. #with open('sample.csv', newline='', encoding='utf-8') as f:
  28. # reader = csv.reader(f)
  29. # for row in reader:
  30. # print(row)
  31. #import csv
  32. #with open('sample', newline='') as f:
  33. # reader = csv.reader(f, delimiter=',', quoting=csv.QUOTE_NONE)
  34. # for row in reader:
  35. # print(row)
  36. #import csv
  37. #with open('sample.csv', newline='') as csvfile:
  38. # reader = csv.DictReader(csvfile)
  39. # for row in reader:
  40. # print(row['policyID'], row['statecode'], row['county'])
  41. from io import StringIO
  42. import csv
  43. string = """policyID,statecode,county,eq_site_limit,hu_site_limit,fl_site_limit,fr_site_limit,tiv_2011,tiv_2012,eq_site_deductible,hu_site_deductible,fl_site_deductible,fr_site_deductible,point_latitude,point_longitude,line,construction,point_granularity
  44. 119736,FL,CLAY COUNTY,498960,498960,498960,498960,498960,792148.9,0,9979.2,0,0,30.102261,-81.711777,Residential,Masonry,1
  45. 448094,FL,CLAY COUNTY,1322376.3,1322376.3,1322376.3,1322376.3,1322376.3,1438163.57,0,0,0,0,30.063936,-81.707664,Residential,Masonry,3
  46. 206893,FL,CLAY COUNTY,190724.4,190724.4,190724.4,190724.4,190724.4,192476.78,0,0,0,0,30.089579,-81.700455,Residential,Wood,1
  47. 333743,FL,CLAY COUNTY,0,79520.76,0,0,79520.76,86854.48,0,0,0,0,30.063236,-81.707703,Residential,Wood,3
  48. 172534,FL,CLAY COUNTY,0,254281.5,0,254281.5,254281.5,246144.49,0,0,0,0,30.060614,-81.702675,Residential,Wood,1
  49. 785275,FL,CLAY COUNTY,0,515035.62,0,0,515035.62,884419.17,0,0,0,0,30.063236,-81.707703,Residential,Masonry,3
  50. 995932,FL,CLAY COUNTY,0,19260000,0,0,19260000,20610000,0,0,0,0,30.102226,-81.713882,Commercial,Reinforced Concrete,1
  51. 223488,FL,CLAY COUNTY,328500,328500,328500,328500,328500,348374.25,0,16425,0,0,30.102217,-81.707146,Residential,Wood,1
  52. 433512,FL,CLAY COUNTY,315000,315000,315000,315000,315000,265821.57,0,15750,0,0,30.118774,-81.704613,Residential,Wood,1"""
  53. f = StringIO(scsv)
  54. reader = csv.reader(f, delimiter=',')
  55. for row in reader:
  56. print(','.join(row))