Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import matplotlib.pyplot as plt
- df = pd.read_csv('TCBT.csv', sep = ',', encoding = 'CP866')
- napravlenie = df.values[:, 0]
- period = df.values[:, 1]
- country = df.values[:, 2]
- tnved = df.values[:, 3]
- cost = df.values[:, 5]
- netto = df.values[:, 6]
- index = []
- for i in range(len(tnved)):
- if tnved[i] == '2401':
- index.append(i)
- newindex = []
- for i in index:
- if napravlenie[i] == 'ИМ':
- newindex.append(i)
- newcountry = []
- for i in newindex:
- newcountry.append(country[i])
- newperiod = []
- for i in newindex:
- newperiod.append(period[i])
- newnetto = []
- for i in newindex:
- newnetto.append(netto[i] / 1000)
- newcost = []
- for i in newindex:
- newcost.append(cost[i] / 1000)
- 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 = []
- # Крупнейшие импортеры табака в Россию (по количеству)
- value = 0
- values = []
- for i in places:
- for j in i:
- value += newnetto[j]
- values.append(value)
- value = 0
- dic = {values[i]: uniquecountry[i] for i in range(len(uniquecountry))}
- print(dic)
- values.sort(reverse = True)
- largest_import = values[:10]
- largest_dealers = []
- for i in largest_import:
- largest_dealers.append(dic[i])
- # Крупнейшие импортеры табака в Россию (по стоимости)
- value2 = 0
- values2 = []
- for i in places:
- for j in i:
- value2 += newcost[j]
- values2.append(value2)
- value2 = 0
- dic2 = {values2[i]: uniquecountry[i] for i in range(len(uniquecountry))}
- print(dic2)
- values2.sort(reverse = True)
- expensive_cost = values2[:10]
- expensive_dealers = []
- for i in expensive_cost:
- expensive_dealers.append(dic2[i])
- # Общий импорт табака в Россию по годам
- netto_IM_2013 = netto_IM_2014 = netto_IM_2015 = netto_IM_2016 = 0
- for i in range(len(newperiod)):
- if newperiod[i] == 2013:
- netto_IM_2013 += newnetto[i]
- elif newperiod[i] == 2014:
- netto_IM_2014 += newnetto[i]
- elif newperiod[i] == 2015:
- netto_IM_2015 += newnetto[i]
- elif newperiod[i] == 2016:
- netto_IM_2016 += newnetto[i]
- all_netto = netto_IM_2013 + netto_IM_2014 + netto_IM_2015 + netto_IM_2016
- sort_counries_on_netto = []
- percent = []
- c = 0
- for i in values:
- sort_counries_on_netto.append(dic[i])
- c = float('{:.3f}'.format(i / all_netto * 100))
- percent.append(c)
- # rating = pd.DataFrame({'Количество, т': values, '% от всего импорта': percent}, index = sort_counries_on_netto)
- # # print(rating)
- # # rating.to_csv('Рейтинг.csv', encoding = 'Windows-1251')
- # Импорт из Бразилии по годам
- 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, color='#CC6633', zorder=2)
- plt.title('Крупнейшие импортеры табака в Россию')
- plt.xlabel('Страны')
- plt.ylabel('Количество табака, т')
- plt.grid(True)
- fig = plt.figure()
- plt.bar(expensive_dealers, expensive_cost, color = '#440000', zorder = 2)
- plt.title('Крупнейшие импортеры табака в Россию')
- plt.xlabel('Страны')
- plt.ylabel('Стоимость, $ тыс.')
- plt.grid(True)
- fig = plt.figure()
- years_IM = ['2013', '2014', '2015', '2016']
- netto_IM = [netto_IM_2013, netto_IM_2014, netto_IM_2015, netto_IM_2016]
- plt.title('Общий импорт табака в Россию по годам')
- plt.bar(years_IM, netto_IM, width = 0.5, color = '#CC6633', zorder = 2)
- plt.ylabel('Количество табака, т')
- plt.grid(True)
- 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.3, color = '#440000', label = 'Стоимость табака, $ тыс.',
- zorder = 2)
- plt.bar([x + 0.4 for x in range(len(years))], netto_on_years,
- width = 0.3, color = '#CC6633', label = 'Количество табака, т',
- zorder = 2)
- plt.xticks(range(len(years)), years)
- plt.legend(loc = 'upper right')
- plt.grid(True)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement