Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. import xlrd
  2. import openpyxl
  3. import numpy as n
  4. from numpy import *
  5.  
  6. file_location = "C:/Users/test.xlsx"
  7. sheet_index = 2
  8. range_hist = 23
  9. lifetime_data = 3
  10. low_salesyear = 1990
  11. upp_salesyear = 2005
  12. col_filter1 = 14
  13. filter_value1 = 1
  14. col_filter2 = 18
  15. filter_value2 = 5
  16.  
  17.  
  18. # open excel-file
  19. workbook = xlrd.open_workbook(file_location)
  20.  
  21.  
  22. # get sheet, index always start at 0
  23. sheet = workbook.sheet_by_index(sheet_index)
  24.  
  25.  
  26. #read all data in the sheet
  27. list_device = [[sheet.cell_value(r,c) for c in range (sheet.ncols)] for r in range (1,sheet.nrows)]
  28.  
  29.  
  30. # filter list for independent variables
  31. listnew = list(filter(lambda x: x[col_filter1]==filter_value1 and x[col_filter2]==filter_value2 and low_salesyear <= x[0] <= upp_salesyear, list_device))
  32. # low_salesyear <= x[0] <= upp_salesyear and
  33.  
  34.  
  35. # select relevant data from filtered list for histogram and store it in list for histogram
  36.  
  37. list_for_hist = []
  38. for i in range(len(listnew)):
  39. list_for_hist.append(listnew[i][lifetime_data])
  40. print (list_for_hist)
  41.  
  42.  
  43. # create array from list
  44. array_for_hist = array(list_for_hist)
  45.  
  46.  
  47. # create histogram
  48. hist = np.histogram(array_for_hist, bins = range(0,int(range_hist)))
  49. print (hist)
  50.  
  51. [8.0, 19.0, 4.0, 4.0, 8.0, 3.0, 13.0, '', 10.0, 7.0, 17.0, 16.0, 8.0,
  52. 6.0, 13.0, 8.0, 7.0, 11.0, 12.0, 13.0, 4.0, 6.0, 5.0, 19.0, 8.0, 6.0]
  53.  
  54. (array([ 0, 10, 0, 1, 3, 1, 3, 2, 5, -25, 1, 1, 1,
  55. 3, 0, 0, 1, 1, 0, 2, 0, 0]), array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
  56. 17, 18, 19, 20, 21, 22]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement