Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- import matplotlib.pyplot as plt
- rawdata = []
- with open('TCBT.csv', 'r', encoding='CP866') as file:
- r = csv.reader(file)
- for line in r:
- rawdata.append(line)
- # print(rawdata)
- napravlenie = [x[0] for x in rawdata]
- period = [x[1] for x in rawdata]
- country = [x[2] for x in rawdata]
- tnved = [x[3] for x in rawdata]
- cost = [x[5] for x in rawdata]
- netto = [x[6] for x in rawdata]
- index = []
- for i in range(len(tnved)):
- if tnved[i] == '2401':
- index.append(i)
- # print(index)
- newindex = []
- for i in index:
- if napravlenie[i] == "ИМ":
- newindex.append(i)
- # print(newindex)
- newcountry = []
- for i in newindex:
- newcountry.append(country[i])
- # print(newcountry)
- newperiod = []
- for i in newindex:
- newperiod.append(period[i])
- # print(newperiod)
- newnetto = []
- for i in newindex:
- newnetto.append(float(netto[i]) / 1000) # Количество ввозимого табака в тоннах
- # print(newnetto)
- newcost = []
- for i in newindex:
- newcost.append(float(cost[i]) / 1000) # Стоимость табака в $ тыс.
- # print(newcost)
- uniquecountry = []
- place = []
- places = []
- for i in newcountry:
- if i not in uniquecountry:
- uniquecountry.append(i)
- for j in range(len(uniquecountry)):
- for i in range(len(newcountry)):
- if uniquecountry[j] == newcountry[i]:
- place.append(i)
- places.append(place)
- place = []
- # print(uniquecountry)
- # print(places)
- value = 0
- values = []
- for i in places:
- for j in i:
- value += newnetto[j]
- values.append(value)
- value = 0
- # print(values)
- dic = {values[i]: uniquecountry[i] for i in range(len(uniquecountry))}
- # print(dic)
- values.sort()
- largest_import = values[-10:]
- largest_dealers = []
- for i in largest_import:
- largest_dealers.append(dic[i])
- # print(largest_dealers)
- # Запись рейтинга в CSV файл
- iposition=[]
- with open("Рейтинг.csv", "a", newline = '') as file:
- for i in values:
- iposition.append(i)
- iposition.append(dic[i])
- writer = csv.writer(file)
- writer.writerow(iposition)
- iposition = []
- value2 = 0
- values2 = []
- for i in places:
- for j in i:
- value2 += newcost[j]
- values2.append(value2)
- value2 = 0
- # print(values2)
- dic2 = {values2[i]: uniquecountry[i] for i in range(len(uniquecountry))}
- # print(dic2)
- values2.sort()
- expensive_cost = values2[-10:]
- expensive_dealers = []
- for i in expensive_cost:
- expensive_dealers.append(dic2[i])
- periodBR = []
- costBR = []
- nettoBR = []
- for i in range(len(newcountry)):
- if newcountry[i] == 'BR':
- periodBR.append(newperiod[i])
- costBR.append(newcost[i])
- nettoBR.append(newnetto[i])
- cost2013 = netto2013 = cost2014 = netto2014 = cost2015 = netto2015 = cost2016 = netto2016 = 0
- for i in range(len(periodBR)):
- if periodBR[i] == '2013':
- cost2013 += costBR[i]
- netto2013 += nettoBR[i]
- elif periodBR[i] == '2014':
- cost2014 += costBR[i]
- netto2014 += nettoBR[i]
- elif periodBR[i] == '2015':
- cost2015 += costBR[i]
- netto2015 += nettoBR[i]
- elif periodBR[i] == '2016':
- cost2016 += costBR[i]
- netto2016 += nettoBR[i]
- fig = plt.figure()
- plt.bar(largest_dealers, largest_import)
- plt.title('Крупнейшие импортеры табака в Россию')
- plt.xlabel('Страны')
- plt.ylabel('Количество табака, т')
- plt.grid(True)
- # plt.show()
- fig = plt.figure()
- plt.bar(expensive_dealers, expensive_cost, color = 'red')
- plt.title('Крупнейшие импортеры табака в Россию')
- plt.xlabel('Страны')
- plt.ylabel('Стоимость, $ тыс.')
- plt.grid(True)
- # plt.show()
- fig = plt.figure()
- years = ['2013', '2014', '2015', '2016']
- cost_on_years = [cost2013, cost2014, cost2015, cost2016]
- netto_on_years = [netto2013, netto2014, netto2015, netto2016]
- plt.title('Импорт из Бразилии по годам')
- plt.bar([x + 0.05 for x in range(len(years))], cost_on_years,
- width = 0.2, color = 'red', alpha = 0.7, label = 'Стоимость табака, $ тыс.',
- zorder = 2)
- plt.bar([x + 0.3 for x in range(len(years))], netto_on_years,
- width = 0.2, color = 'blue', alpha = 0.7, label = 'Количество табака, т',
- zorder = 2)
- plt.legend(loc = 'upper right')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement