Блог им. Albus
Russian Federation has the 6 place in the world in the number of Beehives
Российская Федерация занимает 6 место в мире по количеству ульев
Russian Federation has the 6 place in the world in the number of Ducks
Российская Федерация занимает 6 место в мире по количеству уток
Russian Federation has the 7 place in the world in the number of Geese and guinea fowls
Российская Федерация занимает 7 место в мире по количеству гусей и цесарок
Russian Federation has the 7 place in the world in the number of Pigs
Российская Федерация занимает 7 место в мире по количеству свиней
Russian Federation has the 7 place in the world in the number of Rabbits and hares
Российская Федерация занимает 7 место в мире по количеству кроликов и зайцев
Russian Federation has the 9 place in the world in the number of Chickens
Российская Федерация занимает 9 место в мире по количеству цыплят
Russian Federation has the 9 place in the world in the number of Horses
Российская Федерация занимает 9 место в мире по количеству лошадей
Russian Federation has the 10 place in the world in the number of Turkeys
Российская Федерация занимает 10 место в мире по количеству индеек
Russian Federation has the 16 place in the world in the number of Sheep
Российская Федерация занимает 16 место в мире по количеству овец
Russian Federation has the 18 place in the world in the number of Cattle
Российская Федерация занимает 18 место в мире по количеству крупного рогатого скота
---
Код скрипта:
из внешних библиотек надо установить pandas и googletrans:
pip install pandas
pip install googletrans
# -*- coding: utf-8 -*-
######
from zipfile import ZipFile
import io
from urllib.request import urlopen
import pandas as pd
from time import sleep
from googletrans import Translator
country = 'Russian Federation'
url = "http://fenixservices.fao.org/faostat/static/bulkdownloads/Production_Livestock_E_All_Data_(Normalized).zip"
print ('Качаем данные с сайта Продовольственной организации ООН (FAO)')
file = ZipFile(io.BytesIO(urlopen(url).read()))
type_dict = {'Area Code': 'int64', 'Area' : 'object', 'Item Code' : 'int64', 'Item' : 'object','Element Code' : 'int64',
'Element' : 'object', 'Year Code' : 'int64', 'Year' : 'int64', 'Unit' : 'object', 'Value' : 'float64',
'Flag' : 'object', 'Note' : 'object'}
print ('Из скачанного архива берём файл Production_Livestock_E_All_Data_(Normalized).csv \nСоздаём структуру данных DataFrame')
df = pd.read_csv(file.open("Production_Livestock_E_All_Data_(Normalized).csv"), encoding='latin1', dtype=type_dict,
usecols=["Area Code", "Area", "Item Code", "Item", "Element", "Year", "Unit", "Value"])
max_year = df['Year'].max()
print ("Самый близкий доступный год:" + str(max_year))
df = df[df['Year'] == max_year]
df = df[df['Area Code'] < 5000] #убираем макрорегионы типа Африка, Европа. Нам нужны только страны.
# Убираем лишний Китай:
df = df[df['Area Code'] != 96] # 96 China, Hong Kong SAR
df = df[df['Area Code'] != 128] # 128 China, Macao SAR
df = df[df['Area Code'] != 41] # 41 China, mainland
df = df[df['Area Code'] != 214] # 214 China, Taiwan Province of
df = df[df['Item Code'] != 1746] #Убираем Cattle and Buffaloes (они есть по отдельности)
df = df[df['Item Code'] != 2029] #Убираем Poultry Birds (они есть по отдельности)
df_rank = df
df_rank['Rank'] = df_rank.groupby('Item')['Value'].rank(ascending=False)
df_rank = df_rank[df_rank['Area']==country]
df_rank = df_rank[['Item', 'Rank']]
df_rank = df_rank.sort_values(by=['Rank'])
rank_list = df_rank.values.tolist()
open('rank.txt', 'w').close()
for item in rank_list:
try:
mesto = int(item[1])
if mesto <=20:
line = country + ' has the ' + str(mesto) + ' place in the world in the number of ' + item[0]
translator = Translator()
line_russian = translator.translate(line, dest='ru').text
combined_line = line + '\n' + line_russian
print (combined_line)
with open('rank.txt', 'a', encoding='utf8') as file:
file.write(combined_line + '\n')
sleep (1) #засыпаем на несколько секунд, чтобы гугл не забанил за множественные запросы.
except:
pass
Скачать этот скрипт в виде файла
Ukraine has the 5 place in the world in the number of Rabbits and hares
Украина занимает 5 место в мире по количеству кроликов и зайцев
Ukraine has the 6 place in the world in the number of Geese and guinea fowls
Украина занимает 6 место в мире по количеству гусей и цесарок
Ukraine has the 12 place in the world in the number of Ducks
Украина занимает 12 место в мире по количеству уток
Ukraine has the 20 place in the world in the number of Chickens
Украина занимает 20 место в мире по количеству цыплят
Занятная автоматизация, поиска хоть каких-то достижений путина ))
Тогда эта стата ни о чём —
можно быть на 1-м месте и всё съедать внутри.
Еще и не всем хватит ))
Это не сложно, надо найти такую же базу по численности населения и настроить скрипт качать с неё данные.
Как-нибудь допилю.
«Власть у нас относится к своему населению, как к домашним животным» © Э.Лимонов.
Самый длинный список, конечно же по Китаю:
China has the 1 place in the world in the number of Goats
Китай занимает 1 место в мире по количеству коз
China has the 1 place in the world in the number of Sheep
Китай занимает 1 место в мире по количеству овец
China has the 1 place in the world in the number of Rabbits and hares
Китай занимает 1 место в мире по количеству кроликов и зайцев
China has the 1 place in the world in the number of Pigs
Китай занимает 1 место в мире по количеству свиней
China has the 1 place in the world in the number of Geese and guinea fowls
Китай занимает 1 место в мире по количеству гусей и цесарок
China has the 1 place in the world in the number of Ducks
Китай занял 1 место в мире по количеству уток
China has the 1 place in the world in the number of Sheep and Goats
Китай занимает 1 место в мире по количеству овец и коз
China has the 1 place in the world in the number of Chickens
Китай занимает 1 место в мире по количеству кур
China has the 2 place in the world in the number of Pigeons, other birds
Китай занимает 2 место в мире по количеству голубей, других птиц
China has the 2 place in the world in the number of Beehives
Китай занимает 2 место в мире по количеству ульев
China has the 3 place in the world in the number of Mules
Китай занимает 3 место в мире по количеству мулов
China has the 3 place in the world in the number of Buffaloes
Китай занимает 3 место в мире по количеству буйволов
China has the 4 place in the world in the number of Cattle
Китай занимает 4 место в мире по количеству крупного рогатого скота
China has the 5 place in the world in the number of Horses
Китай занимает 5 место в мире по количеству лошадей
China has the 6 place in the world in the number of Asses
Китай занимает 6 место в мире по количеству ослов
China has the 16 place in the world in the number of Camels
Китай занимает 16 место в мире по количеству верблюдов
А как найти страну, которая занимает 1-е место по количеству ослов? Баранов?
С уважением
P.S. Или баран и овца — это монопенисуально?
Так что индейками, овцами и прочими рогатыми скотами надо не гордится, а недоумевать — «чо так мало-то?»