# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# ## The most Trending programming languages used in egypt last 3 years !!!

# We Will Go Throudg data analysis using Stackoverflow’s 2017,2018 and 2019 Annual Developer Survey.

# <img src="programmin.jpg"
#      alt="Markdown Monster icon"
#      style="float: left; margin-right: 10px;" />

# ### Introduction

# +
import numpy as np
import pandas as pd
from collections import Counter

# to visualise al the columns in the dataframe
pd.pandas.set_option('display.max_columns', None)

# to make plots
import matplotlib.pyplot as plt
# %matplotlib inline

# to change plot style
# sns.set(style="darkgrid")

# to ignore warnings
import warnings
warnings.filterwarnings("ignore")
# %matplotlib inline
# -

df2019=pd.read_csv("2019/survey_results_public.csv")
df2018=pd.read_csv("2018/survey_results_public.csv")
df2017=pd.read_csv("2017/survey_results_public.csv")

# ### UnderstandingData 
# let's have a quick look on Data 

df2018.info()

df2017.head()


# ### 1-What are The kinds of developers?

def display_bar_chart(df, column, title):
    '''
    Displays a bar chart with a title
    Returns:None
    
    '''
    status_vals = df[column].value_counts()
    dfp=(status_vals[:10]/df.shape[0])
    dfp.sort_values().plot(kind="barh");
    plt.title(title);


display_bar_chart(df2017, "Professional", "kinds of developers")


# ### 2-what is egyptien developers ratio all over the wold?

dfco = df2017.query("Country=='Egypt'")
ratio=dfco.shape[0]/df2017.shape[0]*100
print("egyption developers",ratio,"%")

# ### 3-what is the ratio of males and females devolpers in egypt?

d1=df2017.query("Country=='Egypt'")
d1=d1["Gender"].value_counts()
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
ax.axis('equal')
explode = (0.1, 0.1, 0)
d1.plot(kind="pie", shadow=True,explode=explode,autopct='%1.2f%%')


# ### 4-What programming languages are most used to work in egypt last 3 years?
# ### 5-which programming languages are most required in egypt last 3 years?

def get_countery_data(df,country_col,country_name,columns):
    ''' grouping by countery '''
    df_copy =df 
    for column in columns:
        df_copy=df_copy[df_copy[country_col]==country_name].dropna(subset=[column])
    return df_copy 


egypt2017=get_countery_data(df2017, 'Country', 'Egypt', ['HaveWorkedLanguage', 'WantWorkLanguage'])
egypt2018=get_countery_data(df2018, 'Country', 'Egypt', ['LanguageWorkedWith', 'LanguageDesireNextYear'])
egypt2019=get_countery_data(df2019, 'Country', 'Egypt', ['LanguageWorkedWith', 'LanguageDesireNextYear'])


def split_column(df, column):
    ''' Split column by ;,
        returns a splited series.
    '''
    
    df_copy = df
    column_series = df_copy[column].apply(lambda x: x.split(';'))
    
    return column_series


# +
# Splitting the Data Frame by column into a Series. 
worked_lang_2017 = split_column(egypt2017, 'HaveWorkedLanguage')
wanted_lang_2017 = split_column(egypt2017, 'WantWorkLanguage')

worked_lang_2018 = split_column(egypt2018, 'LanguageWorkedWith')
wanted_lang_2018 = split_column(egypt2018, 'LanguageDesireNextYear')

worked_lang_2019 = split_column(egypt2019, 'LanguageWorkedWith')
wanted_lang_2019 = split_column(egypt2019, 'LanguageDesireNextYear')


# +
def disarray(array_list):
    ''' Flat a nested list,
        returns a flat list.
    '''
    
    objects = []
    
    for row in array_list:
        for obj in row:
            objects.append(obj.strip())
            
    return objects

# Flatting nested list objects.
list_worked_languages_2017 = disarray(worked_lang_2017)
list_wanted_languages_2017 = disarray(wanted_lang_2017)

list_worked_languages_2018 = disarray(worked_lang_2018)
list_wanted_languages_2018 = disarray(wanted_lang_2018)

list_worked_languages_2019 = disarray(worked_lang_2019)
list_wanted_languages_2019 = disarray(wanted_lang_2019)


# +
def group_list(data_list, year):
    ''' Group by count to a list,
        returns a result dict.
    '''
    grouped_list = dict(Counter(data_list))
    grouped_dict = [{'Programming Language':key, 'Count': value, 'Year': year} for key, value in grouped_list.items()]
    
    return grouped_dict

# Groping a list and creating a dict.
dict_worked_languages_2017 = group_list(list_worked_languages_2017, '2017')
dict_wanted_languages_2017 = group_list(list_wanted_languages_2017, '2017')

dict_worked_languages_2018 = group_list(list_worked_languages_2018, '2018')
dict_wanted_languages_2018 = group_list(list_wanted_languages_2018, '2018')

dict_worked_languages_2019 = group_list(list_worked_languages_2019, '2019')
dict_wanted_languages_2019 = group_list(list_wanted_languages_2019, '2019')

# -

dict_worked_languages_2019

df1_1=pd.DataFrame(dict_worked_languages_2017).sort_values(by=['Count'], ascending=False).head(10)
df1_2=pd.DataFrame(dict_wanted_languages_2017).sort_values(by=['Count'], ascending=False).head(10)
df2_1=pd.DataFrame(dict_worked_languages_2018).sort_values(by=['Count'], ascending=False).head(10)
df2_2=pd.DataFrame(dict_wanted_languages_2018).sort_values(by=['Count'], ascending=False).head(10)
df3_1=pd.DataFrame(dict_worked_languages_2019).sort_values(by=['Count'], ascending=False).head(10)
df3_2=pd.DataFrame(dict_wanted_languages_2019).sort_values(by=['Count'], ascending=False).head(10)


df3_1

ax1=df1_1.plot.bar(x="Programming Language",y="Count",edgecolor="orange")
plt.title("top 10 programming languages worked in egypt 2017");

ax1=df1_2.plot.bar(x="Programming Language",y="Count",color="orange",edgecolor="blue")
plt.title("top 10 programming languages wanted in egypt 2017");

ax1=df2_1.plot.bar(x="Programming Language",y="Count",edgecolor="orange")
plt.title("top 10 programming languages worked in egypt 2018");

ax1=df2_2.plot.bar(x="Programming Language",y="Count",color="orange",edgecolor="blue")
plt.title("top 10 programming languages wanted in egypt 2018");

ax1=df3_1.plot.bar(x="Programming Language",y="Count",edgecolor="orange")
plt.title("top 10 programming languages worked in egypt 2019");

ax1=df3_2.plot.bar(x="Programming Language",y="Count",color="orange",edgecolor="blue")
plt.title("top 10 programming languages wanted in egypt 2019");

# ### Evaluate the Results
# We then looked at the most used programming languages vs wanted in 2017,2018 and 2019 in Egypt and it’s clear that Younger programming languages like Python have been well-deserved to be learned, but the oldest ones still have their value and are being much demanded.

# ### References
#
# Stackoverflow Developer Survey Data: https://insights.stackoverflow.com/survey <br/>
# Medium link: https://medium.com/@himamohamed9688/what-are-the-most-trending-programming-languages-in-egypt-in-the-last-3-years-52789bc8d236

StarcoderdataJupyterScriptsDedupFiltered