Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.24 KB | None | 0 0
  1. import pandas as pd
  2. import matplotlib.pyplot as plt
  3.  
  4. df = pd.read_csv('TCBT.csv', sep = ',', encoding = 'CP866')
  5.  
  6. napravlenie = df.values[:, 0]
  7. period = df.values[:, 1]
  8. country = df.values[:, 2]
  9. tnved = df.values[:, 3]
  10. cost = df.values[:, 5]
  11. netto = df.values[:, 6]
  12.  
  13. index = []
  14. for i in range(len(tnved)):
  15. if tnved[i] == '2401':
  16. index.append(i)
  17.  
  18. newindex = []
  19. for i in index:
  20. if napravlenie[i] == 'ИМ':
  21. newindex.append(i)
  22.  
  23. newcountry = []
  24. for i in newindex:
  25. newcountry.append(country[i])
  26.  
  27. newperiod = []
  28. for i in newindex:
  29. newperiod.append(period[i])
  30.  
  31. newnetto = []
  32. for i in newindex:
  33. newnetto.append(netto[i] / 1000)
  34.  
  35. newcost = []
  36. for i in newindex:
  37. newcost.append(cost[i] / 1000)
  38.  
  39. uniquecountry = []
  40. place = []
  41. places = []
  42. for i in newcountry:
  43. if i not in uniquecountry:
  44. uniquecountry.append(i)
  45. for j in range(len(uniquecountry)):
  46. for i in range(len(newcountry)):
  47. if uniquecountry[j] == newcountry[i]:
  48. place.append(i)
  49. places.append(place)
  50. place = []
  51.  
  52. # Крупнейшие импортеры табака в Россию (по количеству)
  53. value = 0
  54. values = []
  55. for i in places:
  56. for j in i:
  57. value += newnetto[j]
  58. values.append(value)
  59. value = 0
  60. dic = {values[i]: uniquecountry[i] for i in range(len(uniquecountry))}
  61. print(dic)
  62. values.sort(reverse = True)
  63. largest_import = values[:10]
  64. largest_dealers = []
  65. for i in largest_import:
  66. largest_dealers.append(dic[i])
  67.  
  68. # Крупнейшие импортеры табака в Россию (по стоимости)
  69. value2 = 0
  70. values2 = []
  71. for i in places:
  72. for j in i:
  73. value2 += newcost[j]
  74. values2.append(value2)
  75. value2 = 0
  76. dic2 = {values2[i]: uniquecountry[i] for i in range(len(uniquecountry))}
  77. print(dic2)
  78. values2.sort(reverse = True)
  79. expensive_cost = values2[:10]
  80. expensive_dealers = []
  81. for i in expensive_cost:
  82. expensive_dealers.append(dic2[i])
  83.  
  84. # Общий импорт табака в Россию по годам
  85. netto_IM_2013 = netto_IM_2014 = netto_IM_2015 = netto_IM_2016 = 0
  86. for i in range(len(newperiod)):
  87. if newperiod[i] == 2013:
  88. netto_IM_2013 += newnetto[i]
  89. elif newperiod[i] == 2014:
  90. netto_IM_2014 += newnetto[i]
  91. elif newperiod[i] == 2015:
  92. netto_IM_2015 += newnetto[i]
  93. elif newperiod[i] == 2016:
  94. netto_IM_2016 += newnetto[i]
  95.  
  96. all_netto = netto_IM_2013 + netto_IM_2014 + netto_IM_2015 + netto_IM_2016
  97.  
  98. sort_counries_on_netto = []
  99. percent = []
  100. c = 0
  101. for i in values:
  102. sort_counries_on_netto.append(dic[i])
  103. c = float('{:.3f}'.format(i / all_netto * 100))
  104. percent.append(c)
  105.  
  106. # rating = pd.DataFrame({'Количество, т': values, '% от всего импорта': percent}, index = sort_counries_on_netto)
  107. # # print(rating)
  108. # # rating.to_csv('Рейтинг.csv', encoding = 'Windows-1251')
  109.  
  110. # Импорт из Бразилии по годам
  111. periodBR = []
  112. costBR = []
  113. nettoBR = []
  114. for i in range(len(newcountry)):
  115. if newcountry[i] == 'BR':
  116. periodBR.append(newperiod[i])
  117. costBR.append(newcost[i])
  118. nettoBR.append(newnetto[i])
  119. cost2013 = netto2013 = cost2014 = netto2014 = cost2015 = netto2015 = cost2016 = netto2016 = 0
  120. for i in range(len(periodBR)):
  121. if periodBR[i] == '2013':
  122. cost2013 += costBR[i]
  123. netto2013 += nettoBR[i]
  124. elif periodBR[i] == '2014':
  125. cost2014 += costBR[i]
  126. netto2014 += nettoBR[i]
  127. elif periodBR[i] == '2015':
  128. cost2015 += costBR[i]
  129. netto2015 += nettoBR[i]
  130. elif periodBR[i] == '2016':
  131. cost2016 += costBR[i]
  132. netto2016 += nettoBR[i]
  133.  
  134.  
  135.  
  136. fig = plt.figure()
  137. plt.bar(largest_dealers, largest_import, color='#CC6633', zorder=2)
  138. plt.title('Крупнейшие импортеры табака в Россию')
  139. plt.xlabel('Страны')
  140. plt.ylabel('Количество табака, т')
  141. plt.grid(True)
  142.  
  143. fig = plt.figure()
  144. plt.bar(expensive_dealers, expensive_cost, color = '#440000', zorder = 2)
  145. plt.title('Крупнейшие импортеры табака в Россию')
  146. plt.xlabel('Страны')
  147. plt.ylabel('Стоимость, $ тыс.')
  148. plt.grid(True)
  149.  
  150. fig = plt.figure()
  151. years_IM = ['2013', '2014', '2015', '2016']
  152. netto_IM = [netto_IM_2013, netto_IM_2014, netto_IM_2015, netto_IM_2016]
  153. plt.title('Общий импорт табака в Россию по годам')
  154. plt.bar(years_IM, netto_IM, width = 0.5, color = '#CC6633', zorder = 2)
  155. plt.ylabel('Количество табака, т')
  156. plt.grid(True)
  157.  
  158. fig = plt.figure()
  159. years = ['2013', '2014', '2015', '2016']
  160. cost_on_years = [cost2013, cost2014, cost2015, cost2016]
  161. netto_on_years = [netto2013, netto2014, netto2015, netto2016]
  162. plt.title('Импорт из Бразилии по годам')
  163. plt.bar([x + 0.05 for x in range(len(years))], cost_on_years,
  164. width = 0.3, color = '#440000', label = 'Стоимость табака, $ тыс.',
  165. zorder = 2)
  166. plt.bar([x + 0.4 for x in range(len(years))], netto_on_years,
  167. width = 0.3, color = '#CC6633', label = 'Количество табака, т',
  168. zorder = 2)
  169. plt.xticks(range(len(years)), years)
  170. plt.legend(loc = 'upper right')
  171. plt.grid(True)
  172. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement