# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory

import os
for dirname, _, filenames in os.walk('/kaggle/input'):
    for filename in filenames:
        print(os.path.join(dirname, filename))

# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All" 
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
import matplotlib.pyplot as plt
"""
# **India**
"""
Agriculture=pd.read_csv("../input/world-population-working-in-different-sectors/Agriculture.csv")
Agriculture.head()
India=Agriculture[Agriculture['Country Name']== 'India']
India=India.drop(['Country Code','2020'], axis = 1)
india_Agriculture=India.set_index('Country Name').T.astype(float)
india_Agriculture.plot(figsize=(20,10),marker="o",title="% of total population in agriculture from 1991 to 2019")
plt.xlabel("YEARS")
plt.ylabel("% of total population in agriculture")
plt.legend()
plt.show()
Industry=pd.read_csv("../input/world-population-working-in-different-sectors/Industry.csv")
India=Industry[Industry['Country Name']== 'India']
India=India.drop(['Country Code','2020'], axis = 1)
india_Industry=India.set_index('Country Name').T.astype(float)
india_Industry.plot(figsize=(20,10),marker="o",title="% of total population in Industry from 1991 to 2019")
plt.xlabel("YEARS")
plt.ylabel("% of total population in Industry")
plt.legend()
plt.show()
Service=pd.read_csv("../input/world-population-working-in-different-sectors/Service.csv")
India=Service[Service['Country Name']== 'India']
India=India.drop(['Country Code','2020'], axis = 1)
india_Service=India.set_index('Country Name').T.astype(float)
india_Service.plot(figsize=(20,10),marker="o",title="% of total population in Service from 1991 to 2019")
plt.xlabel("YEARS")
plt.ylabel("% of total population in Service")
plt.legend()
plt.show()
"""
# **LinearRegression Model**
"""
from sklearn.linear_model import LinearRegression
lin=LinearRegression()
india_Agriculture=india_Agriculture.values
india_Industry=india_Industry.values
lin.fit(india_Industry,india_Agriculture)
y_pred=lin.predict(india_Industry)
plt.scatter(india_Industry,india_Agriculture)
plt.plot(india_Industry,y_pred,color='red')
plt.xlabel('Industry Population')
plt.ylabel('Agriculture Population')
plt.title('Agriculture Population v/s Industry Population')
plt.show()
india_Service=india_Service.values
lin.fit(india_Service,india_Agriculture)
plt.scatter(india_Service,india_Agriculture)
plt.plot(india_Service,y_pred,color='red')
plt.xlabel('Service Population')
plt.ylabel('Agriculture Population')
plt.title('Agriculture Population v/s Service Population')
plt.show()
"""
# **Map** 
"""
!pip install pycountry_convert
import pycountry_convert as pc
df_A= Agriculture[(Agriculture["Country Name"]=="Bhutan") |(Agriculture["Country Name"]=="China")|(Agriculture["Country Name"]=='Nepal') |(Agriculture["Country Name"]=='Afghanistan')|(Agriculture["Country Name"]=='India')|(Agriculture["Country Name"]=='Pakistan')|(Agriculture["Country Name"]=='Bangladesh')|(Agriculture["Country Name"]=='Myanmar')]
import plotly.express as px
Agriculture_map = df_A.set_index('Country Name')
temp = pd.DataFrame(Agriculture_map['2019']).reset_index()


temp['iso_alpha'] = temp['Country Name'].apply(lambda x:pc.country_name_to_country_alpha3(x,))
fig = px.choropleth(temp, locations='iso_alpha',
                    color='2019',
                    hover_name='Country Name',
                    color_continuous_scale=px.colors.diverging.RdYlGn,
                   )
fig.update_layout(
    title_text='World map - 2019',
    showlegend=False,
    paper_bgcolor='rgb(248, 248, 255)',
    geo_bgcolor='rgb(248, 248, 255)',
    geo_showframe=False,
    title_font_size=22,
)
fig.show()
df_I= Industry[(Industry["Country Name"]=="Bhutan") |(Industry["Country Name"]=="China")|(Industry["Country Name"]=='Nepal') |(Industry["Country Name"]=='Afghanistan')|(Industry["Country Name"]=='India')|(Industry["Country Name"]=='Pakistan')|(Industry["Country Name"]=='Bangladesh')|(Industry["Country Name"]=='Myanmar')]
Industry_map = df_I.set_index('Country Name')
temp = pd.DataFrame(Industry_map['2019']).reset_index()


temp['iso_alpha'] = temp['Country Name'].apply(lambda x:pc.country_name_to_country_alpha3(x,))
fig = px.choropleth(temp, locations='iso_alpha',
                    color='2019',
                    hover_name='Country Name',
                    color_continuous_scale=px.colors.diverging.RdYlGn,
                   )
fig.update_layout(
    title_text='World map - 2019',
    showlegend=False,
    paper_bgcolor='rgb(248, 248, 255)',
    geo_bgcolor='rgb(248, 248, 255)',
    geo_showframe=False,
    title_font_size=22,
)
fig.show()
df_S= Service[(Service["Country Name"]=="Bhutan") |(Service["Country Name"]=="China")|(Service["Country Name"]=='Nepal') |(Service["Country Name"]=='Afghanistan')|(Service["Country Name"]=='India')|(Service["Country Name"]=='Pakistan')|(Service["Country Name"]=='Bangladesh')|(Service["Country Name"]=='Myanmar')]
Service_map = df_S.set_index('Country Name')
temp = pd.DataFrame(Service_map['2019']).reset_index()


temp['iso_alpha'] = temp['Country Name'].apply(lambda x:pc.country_name_to_country_alpha3(x,))
fig = px.choropleth(temp, locations='iso_alpha',
                    color='2019',
                    hover_name='Country Name',
                    color_continuous_scale=px.colors.diverging.RdYlGn,
                   )
fig.update_layout(
    title_text='World map - 2019',
    showlegend=False,
    paper_bgcolor='rgb(248, 248, 255)',
    geo_bgcolor='rgb(248, 248, 255)',
    geo_showframe=False,
    title_font_size=22,
)
fig.show()