<jupyter_start><jupyter_text>*   **CustomerID** : Id do cliente*   **Gender** : Gênero do Cliente (Masculino: Male, Feminino: Female)*   **Age** : Idade do consumidor (em anos)*   **Annual Income** : Renda Anual do Cliente*   **Spending Score** : Pontual sobre os gastos e comportamento do cliente<jupyter_code>customers.info()
customers.describe()
#verificando a existência de campos nulos
customers.isnull().sum()
customers.sum()
customers['Gender'].count()

customers_null = customers
for col in customers_null.columns:
  customers_null.loc[customers_null.sample(frac=0.1).index, col] = np.nan

print(customers_null)
print("====A======")
print(customers_null.sample(frac=0.1))
print("===B=======")
print(customers_null.isnull().sum())
print("=====C=====")
customers_null.isnull().count()
customers_null.info()
print(customers_null['Gender'][1:10])
x = customers_null.dropna()
x.info()
print(x)
customers_null.info()
customers_null.info()
customers_null.describe()

## Substitui todos os nulos pelo valor médio da coluna
customers_null2 = customers_null.fillna(customers_null.mean())
customers_null.info()
customers_null2.info()
print("----")
customers_null.describe()

print("------")
customers_null2.describe()
boxplot = customers.boxplot(column=['CustomerID','Age','Annual Income (k$)','Spending Score (1-100)'])

customers.mean()
## Outra forma de encontrar outlayers. Usando o desvio normal em desvios padrões.
from scipy import stats
## print(customers['Annual Income (k$)'].values)
z = np.abs(stats.zscore(customers['Annual Income (k$)'].values))
##print(z)
threshold = 2
result = np.where(z > threshold)
print(result)
df_salario_outlayer = customers.iloc[result[0]]

print(df_salario_outlayer)
## df_salario_outlayer
## Imprime histograma por gênero
sns.countplot(x="Gender", data=customers)
plt.title("Dist. quanto ao gênero")
plt.plot()
# Distribuição quanto a idade
customers.hist('Age', bins=35)
plt.title("Dist quanto a idade")
plt.xlabel("Idade")
plt.ylabel("Quantidade")
plt.plot()
## Selecionando 1 coluna de tipo específico ( por exemplo gênero que é object )
cat_df_customers = customers.select_dtypes(include=['object'])
cat_df_customers.head()
replace_map = {'Gender':{'Female':1, 'Male':2}}
labels = cat_df_customers['Gender'].astype('category').cat.categories.tolist()
replace_map_comp = {'Gender' : {k:v for k,v in zip(labels, list(range(1,len(labels)+1))) }}
print(replace_map_comp)
print(labels)
print(replace_map)
## Substituindo os valores de uma coluna
print(replace_map_comp)
customers_replace = pd.read_csv("/content/drive/My Drive/Colab Notebooks/IGTI/atividade-pratica-1/Mall_Customers.csv")
customers_replace['Gender_str'] = customers_replace['Gender']
customers_replace.replace(replace_map_comp, inplace=True)
customers_replace.head()
## Filtrando e selecionando colunas
## df.loc[(df['Salary_in_1000']>=100) & (df['Age']< 60) & (df['FT_Team'].str.startswith('S')),['Name','FT_Team']]
customers_replace.loc[customers_replace['Gender'] == 1, ['Gender_str', 'Age', 'CustomerID']].head()
## Usando o label Encodering do Pandas
customers = pd.read_csv("/content/drive/My Drive/Colab Notebooks/IGTI/atividade-pratica-1/Mall_Customers.csv")
cat_df_customers_lc = customers
cat_df_customers_lc['Gender_str'] = cat_df_customers_lc['Gender']
cat_df_customers_lc['Gender'] = pd.Categorical(cat_df_customers_lc['Gender'])
cat_df_customers_lc.dtypes

cat_df_customers_lc.head()
cat_df_customers_lc['Gender'] = cat_df_customers_lc['Gender'].cat.codes
cat_df_customers_lc.head()
#Usando o label encoding do sklearn

from sklearn.preprocessing import LabelEncoder

le = LabelEncoder()

customers_label = pd.read_csv("/content/drive/My Drive/Colab Notebooks/IGTI/atividade-pratica-1/Mall_Customers.csv")
customers_label['Gender_Str'] = customers_label['Gender']
customers_label['Gender'] = le.fit_transform(customers_label['Gender'])
customers_label.head()
# Usando o One Hot Encoding (Transforma cada categoria em uma coluna com 1/0)
# usando o pandas

customers_hot_enc = pd.read_csv("/content/drive/My Drive/Colab Notebooks/IGTI/atividade-pratica-1/Mall_Customers.csv")
customers_hot_enc = pd.get_dummies(customers_hot_enc)
customers_hot_enc.head()
# Usando o One Hot Encoding (Transforma cada categoria em uma coluna com 1/0)
# usando o Sklearn

from sklearn.preprocessing import OneHotEncoder
ohe = OneHotEncoder()

customers_ohe = pd.read_csv("/content/drive/My Drive/Colab Notebooks/IGTI/atividade-pratica-1/Mall_Customers.csv")
customers_xxx = ohe.fit_transform(customers_ohe['Gender'].values.reshape(-1,1)) ##.toarray()
## customers_xxx.shape
print(customers_xxx)<jupyter_output>(0, 1)	1.0
  (1, 1)	1.0
  (2, 0)	1.0
  (3, 0)	1.0
  (4, 0)	1.0
  (5, 0)	1.0
  (6, 0)	1.0
  (7, 0)	1.0
  (8, 1)	1.0
  (9, 0)	1.0
  (10, 1)	1.0
  (11, 0)	1.0
  (12, 0)	1.0
  (13, 0)	1.0
  (14, 1)	1.0
  (15, 1)	1.0
  (16, 0)	1.0
  (17, 1)	1.0
  (18, 1)	1.0
  (19, 0)	1.0
  (20, 1)	1.0
  (21, 1)	1.0
  (22, 0)	1.0
  (23, 1)	1.0
  (24, 0)	1.0
  :	:
  (175, 0)	1.0
  (176, 1)	1.0
  (177, 1)	1.0
  (178, 1)	1.0
  (179, 1)	1.0
  (180, 0)	1.0
  (181, 0)	1.0
  (182, 1)	1.0
  (183, 0)	1.0
  (184, 0)	1.0
  (185, 1)	1.0
  (186, 0)	1.0
  (187, 1)	1.0
  (188, 0)	1.0
  (189, 0)	1.0
  (190, 0)	1.0
  (191, 0)	1.0
  (192, 1)	1.0
  (193, 0)	1.0
  (194, 0)	1.0
  (195, 0)	1.0
  (196, 0)	1.0
  (197, 1)	1.0
  (198, 1)	1.0
  (199, 1)	1.0
{'fraction_non_alphanumeric': 0.16917010889973713, 'fraction_numerical': 0.05801727375140819, 'mean_word_length': 5.341666666666667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '478245', 'license': 'CC0-1.0', 'n_tokens_mistral': 2387, 'n_tokens_neox': 2196, 'n_words': 457, 'path': 'Mod1/app_pre_processamento.ipynb', 'repo_name': 'spedison/Curso_igti_ML', 'size': '5326'}