# ---
# 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
# ---

import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
# %matplotlib inline

#Cargamos los datos
data = pd.read_csv('Indigenous.csv')
#Exploramos un ejemplo de los datos
data.head()

#Comprobamos que el numero de columnas
print("Número de columnas:", len((data.columns)))
#Contamos el número de filas que hay en nuestro dataset
print("Número de filas:", np.shape(data)[0])

#Comparamos regiones
reg_plot = sns.catplot(x="Reg", kind="count", palette="winter", data=data, size=5)
reg_plot.set_axis_labels( "Región", "Frecuencia")
reg_plot.fig.set_size_inches(8,8)

#Año
data["Year"]=[data["Dat"][i][0:4] for i in range(len(data["Dat"]))]
year_plot = sns.catplot(x="Year", kind="count", palette="summer", data=data, size=5)
year_plot.set_axis_labels( "Año", "Frecuencia")
year_plot.fig.set_size_inches(16,8)

#Comparamos tipos de conflicto
contp_plot = sns.catplot(x="Contp", kind="count", palette="autumn", data=data, size=5)
contp_plot.set_axis_labels( "Tipo de conflicto", "Frecuencia")
contp_plot.fig.set_size_inches(8,8)

#Comparamos naturalezas de los conflictos
contp_plot = sns.catplot(x="Agtp", kind="count", palette="autumn", data=data, size=5)
contp_plot.set_axis_labels( "Naturaleza del conflicto", "Frecuencia")
contp_plot.fig.set_size_inches(8,8)

#Comparamos estados de acuerdos
contp_plot = sns.catplot(x="Status", kind="count", palette="spring", data=data, size=5)
contp_plot.set_axis_labels( "Estado del acuerdo", "Frecuencia")
contp_plot.fig.set_size_inches(8,8)

#Comparamos estados de acuerdos
contp_plot = sns.catplot(x="Stage", kind="count", palette="spring", data=data, size=5)
contp_plot.set_axis_labels( "Fase del proceso de acuerdo", "Frecuencia")
contp_plot.fig.set_size_inches(8,8)

#Países implicados
sns.set(font_scale=1.2)
country_plot = sns.catplot(x="Con", kind="count", palette="cubehelix", data=data, size=5)
country_plot.set_axis_labels( "País/Población indígena", "Frecuencia")
country_plot.fig.set_size_inches(30,8)
country_plot.set_xticklabels(rotation=90)

data["Con"].unique()

# +
#Atributos interesantes
int_attribute=[]
for i in data.columns:
    if data[i].dtypes=="int64" and data[i].sum()>50:
        Int_attribute.append(i)
print(int_attribute)

#Grupos de atributos interesantes
groups = ['GCh', 'GDis', 'GRa', 'GRe', 'GInd', 'GRef', 'GSoc']
gender = ['GeWom']
state_definition = ['StDef']
governance = ['Pol', 'Ele', 'Civso', 'Pubad']
powersharing = ['Polps', 'Terps', 'Eps'] 
human_rights = ['HrGen', 'EqGen', 'HrDem', 'Prot', 'HrFra', 'Med', 'HrCit']
socio_econ = ['Dev', 'DevSoc', 'Bus', 'Tax', 'Ce']
security = ['SsrPol', 'SsrArm', 'SsrDdr', 'SsrPsf'] 
trans_justice = ['TjAm', 'TjVic', 'TjRep', 'TjNR']
# -



# Gráfico de barras de sobreviviviente segun clase
plot = pd.crosstab(index=data["EqGen"],
            columns=data["Reg"]).apply(lambda r: r/r.sum() *100,
                                       axis=1).plot(kind='bar')

data["Terps"].hist(bins=10, ec="black")
plt.title("Histograma avg_month_turnover")
plt.xlabel("Gasto mensual medio")
plt.ylabel("Número de clientes")
plt.show()





# +


plt.figure(figsize=(15,7))
plot = df["Year"].value_counts().sort_index().plot(kind='bar',
                                            title='Años')
plot = df["Status"].value_counts().sort_index().plot(kind='bar',
                                            title='Años')
plot = df["StageSub"][df["Stage"]=="Cea"].value_counts().sort_index().plot(kind='bar',
                                            title='Años')

# +
#Año

data["Year"]=[data["Dat"][i][0:4] for i in range(len(data["Dat"]))]
number=[pd.value_counts(data['Year'])[i] for i in range(len(data["Year"].unique()))]

year_count

# +
tot_reg = [pd.value_counts(data["Reg"])[i] for i in range(len(data["Reg"].unique()))]
REG = data["Reg"].unique()
for i in range(len(data["Reg"])):
    for j in range(len(REG)):
        if data["Reg"][i] == REG[j]:
            data["GCh"][i] = data["GCh"][i]/tot_reg[j]
            
#data.boxplot("Terps")
q1 = np.percentile(data["SsrCrOcr"], 25)
q3 = np.percentile(data["SsrCrOcr"], 75)
#Como solo hay máximos calculamos el valor extremo superior
maximum = q3+(q3-q1)*1.5

#Guardamos los índices de dichos valores extremos
outliers = data[data["SsrCrOcr"]>maximum].index
#Vemos con que tipo de clientes se corresponden
#print(data[data["SsrCrOcr"]>maximum]) #BOSNIA
# -



StarcoderdataJupyterScriptsDedupFiltered