Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. """
  2. Your task is to process the supplied file and use the csv module to extract data from it.
  3. The data comes from NREL (National Renewable Energy Laboratory) website. Each file
  4. contains information from one meteorological station, in particular - about amount of
  5. solar and wind energy for each hour of day.
  6.  
  7. Note that the first line of the datafile is neither data entry, nor header. It is a line
  8. describing the data source. You should extract the name of the station from it.
  9.  
  10. The data should be returned as a list of lists (not dictionaries).
  11. You can use the csv modules "reader" method to get data in such format.
  12. Another useful method is next() - to get the next line from the iterator.
  13. You should only change the parse_file function.
  14. """
  15. import csv
  16. import os
  17.  
  18. DATADIR = ""
  19. DATAFILE = "745090.csv"
  20.  
  21.  
  22. def parse_file(datafile):
  23. name = ""
  24. data = []
  25. with open(datafile,'r') as f:
  26. r = csv.reader(f)
  27. for row in r:
  28. name = name + (row[1])
  29. break
  30. for row in r:
  31. data.append(row)
  32. #return name
  33.  
  34.  
  35.  
  36. # Do not change the line below
  37. return name, data
  38.  
  39.  
  40. def test():
  41. datafile = os.path.join(DATADIR, DATAFILE)
  42. name, data = parse_file(datafile)
  43.  
  44. assert name == "MOUNTAIN VIEW MOFFETT FLD NAS"
  45. assert data[0][1] == "01:00"
  46. assert data[2][0] == "01/01/2005"
  47. assert data[2][5] == "2"
  48.  
  49.  
  50. if __name__ == "__main__":
  51. test()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement