<jupyter_start><jupyter_text>Criando novas colunas<jupyter_code>df['month'] = df['date'].dt.month
df['year'] = df['date'].dt.year
df['month_year'] = f"{df['date'].dt.month}-{df['date'].dt.year}"
df['time_to_reply'] = ((df['time_answer'] - df['date']).dt.days).sort_values(ascending=False)<jupyter_output><empty_output><jupyter_text>Explorando Cidades e Estados - Top 10 cidades com mais reclamações<jupyter_code>df['city'].value_counts()
sns.barplot(data=df.groupby('city')['assessment'].count().reset_index().sort_values(by='assessment', ascending=False)[:10], y="city", x='assessment')
plt.ylabel('')
plt.xlabel('Quantidade')
plt.title('Top 10 cidades com mais reclamações')<jupyter_output><empty_output><jupyter_text>- Top 10 estados com mais reclamações<jupyter_code>df['uf'].value_counts()
sns.barplot(data=df.groupby('uf')['assessment'].count().reset_index().sort_values(by='assessment', ascending=False)[:10], y="uf", x='assessment')
plt.ylabel('')
plt.xlabel('Quantidade')
plt.title('Top 10 estados com mais reclamações')<jupyter_output><empty_output><jupyter_text>- Correlação entre estados e notas<jupyter_code>df['assessment'].value_counts(normalize=True)
plt.figure(figsize=(10,6))
sns.displot(
    df, x="assessment",
    height=3, facet_kws=dict(margin_titles=True),
    kind="hist",
    bins=11
)
plt.ylabel('Quantidade')
plt.xlabel('Notas')
plt.title('Distribuição de Notas')
plt.show()
for state in df['uf'].unique():
    plt.figure(figsize=(10,4))
    sns.barplot(data=y,
                x='index',
                y='Frequency',
                palette='flare')
    plt.y xlim(0 , 10)

    plt.ylabel('Quantidade')
    plt.xlabel('Notas')
    plt.title(state)
    plt.show()
for state in df['uf'].unique():
    plt.figure(figsize=(10,4))
    sns.displot(df.loc[df['uf'] == state],
                color='blue',
                x="assessment",
                height=3, facet_kws=dict(margin_titles=True),
                kind="hist",
                bins=11)
    
    plt.xlim(0 , 10)

    plt.ylabel('Quantidade')
    plt.xlabel('Notas')
    plt.title(state)
    plt.show()<jupyter_output><empty_output><jupyter_text>Tempo de Resposta (em dias)<jupyter_code>df['time_to_reply'].describe()
sns.histplot(data = df,  x='time_to_reply')
plt.xlabel('Tempo de Resposta (Dias)')
plt.ylabel('Quantidade')
plt.show()
months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho"]
def change_name(x):
    if x == 1:
        resp = 'Janeiro'
        return resp
    if x == 2:
        resp = 'Fevereiro'
        return resp
    if x == 3:
        resp = 'Março'
        return resp
    if x == 4:
        resp = 'Abril'
        return resp
    if x == 5:
        resp = 'Maio'
        return resp
    if x == 6:
        resp = 'Junho'
        return resp
df['month'] = df['month'].apply(lambda x: change_name(x))
fig, axs = plt.subplots(3, 2, figsize=(13, 10))
aux = 0
for i in range(0,3):
    for j in range(0,2):
        sns.countplot(x='month', hue = 'resolved', data=df.loc[(df['year'] == 2021)&(df['month'] == months[aux])], ax=axs[i][j])
        axs[i][j].legend(loc="upper right")
        axs[i][j].set_xlabel('Mês')
        axs[i][j].set_ylabel('Número Ocorrências')
        aux +=1
plt.tight_layout()
mean = df.groupby('month')['time_to_reply'].mean().rename('mean_time')
median = df.groupby('month')['time_to_reply'].median().rename('median_time')
mean.index = pd.CategoricalIndex(mean.index, categories=months, ordered=True)
median.index = pd.CategoricalIndex(median.index, categories=months, ordered=True)
mean.index = mean.index.sort_values()
median.index = median.index.sort_values()
fig, ax = plt.subplots(figsize=(13,8))
ax = median.plot(legend = True, label='Mediana')
ax = mean.plot(legend = True, label='Média')
ax.set_ylim([4,14])
ax.set_xlabel('Mês da reclamação')
ax.set_ylabel('Tempo de resposta (Dias)')
plt.show()
fig, ax = plt.subplots(2, figsize=(15,8))
df.groupby('uf')['time_to_reply'].mean().sort_values().plot(kind='bar', ax=ax[0], title='Média do Tempo de Resposta')
df.groupby('uf')['time_to_reply'].median().sort_values().plot(kind='bar', ax=ax[1], title='Mediana do Tempo de Resposta')
ax[0].set_xlabel('Estado')
ax[0].set_ylabel('Tempo de Resposta (Dias)')
ax[1].set_xlabel('Estado')
ax[1].set_ylabel('Tempo de Resposta (Dias)')
plt.tight_layout()
plt.show()
df[['assessment', 'time_to_reply']].corr()<jupyter_output><empty_output><jupyter_text>Horário de reclamação<jupyter_code>df['date'].dt.hour.hist()<jupyter_output><empty_output><jupyter_text>Status da reclamação<jupyter_code>df['resolved'].value_counts()
plt.figure(figsize=(10, 8))
sns.histplot(
    df.loc[(df['resolved'] == 'Resolvido') | (df['resolved'] == 'Não resolvido')],
    x="assessment", hue='resolved',
    bins=11,
    multiple="stack",
    edgecolor=".3",
    linewidth=.5,
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19237937461172086, 'fraction_numerical': 0.016152412507765584, 'mean_word_length': 4.669014084507042, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '361170', 'license': 'MIT', 'n_tokens_mistral': 1944, 'n_tokens_neox': 1820, 'n_words': 290, 'path': 'Projects/ReclameAqui/3AmbevExploratoryAnalysis_v1.ipynb', 'repo_name': 'Renanrbsc/DataScience', 'size': '4829'}