<jupyter_start><jupyter_text>Survey Improvement AnalysisRock n Ribs<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import random

%matplotlib inline
df_survey = pd.read_csv('./rnr_survey_master_table.csv')
df_survey.drop(['Unnamed: 0'],axis=1, inplace=True)
df_survey[0:3]
df_survey.columns<jupyter_output><empty_output><jupyter_text>According with our dataset, we can measure some metrics. On this notebook we are going to analyze this metrics from October 2019:    1. Franchise customer distribution    2. Recommendation rate    3. Food & Drink average    4. Price-Quality rate    5. Client retention    6. Advertising media effectiveness<jupyter_code># Firstly we must convert to datetime format the column date_created
df_survey['date_created'] = pd.to_datetime(df_survey['date_created'])
df_survey['date_created'][0]
# Create October subset
month_in = pd.to_datetime('2019-10-01 00:00:00')
month_fn = pd.to_datetime('2019-10-31 23:59:59')
df_oct_2019 = df_survey[(df_survey['date_created']>=month_in)&(df_survey['date_created']<=month_fn)]

# Create November subset
month_in = pd.to_datetime('2019-11-01 00:00:00')
month_fn = pd.to_datetime('2019-11-30 23:59:59')
df_nov_2019 = df_survey[(df_survey['date_created']>=month_in)&(df_survey['date_created']<=month_fn)]

# Create December subset
month_in = pd.to_datetime('2019-12-01 00:00:00')
month_fn = pd.to_datetime('2019-12-31 23:59:59')
df_dec_2019 = df_survey[(df_survey['date_created']>=month_in)&(df_survey['date_created']<=month_fn)]

# Create January subset
month_in = pd.to_datetime('2020-01-01 00:00:00')
month_fn = pd.to_datetime('2020-01-31 23:59:59')
df_jan_2020 = df_survey[(df_survey['date_created']>=month_in)&(df_survey['date_created']<=month_fn)]

# Create February subset
month_in = pd.to_datetime('2019-02-01 00:00:00')
month_fn = pd.to_datetime('2019-02-28 23:59:59')
df_feb_2020 = df_survey[(df_survey['date_created']>=month_in)&(df_survey['date_created']<=month_fn)]

# Create March subset
month_in = pd.to_datetime('2019-03-01 00:00:00')
month_fn = pd.to_datetime('2019-03-31 23:59:59')
df_mar_2020 = df_survey[(df_survey['date_created']>=month_in)&(df_survey['date_created']<=month_fn)]<jupyter_output><empty_output><jupyter_text>1. Franchise customer distribution<jupyter_code>df_oct_2019.isna().sum()
# Recomendacion is a column without NaN values so we must use to count customers
df_oct_2019.groupby('Franquicia').sum()['Recomendacion']
ber_cust = df_oct_2019.groupby('Franquicia').sum()['Recomendacion'][0]
jar_cust = df_oct_2019.groupby('Franquicia').sum()['Recomendacion'][1]
jur_cust = df_oct_2019.groupby('Franquicia').sum()['Recomendacion'][2]
ln_cust = df_oct_2019.groupby('Franquicia').sum()['Recomendacion'][3]
sjr_cust = df_oct_2019.groupby('Franquicia').sum()['Recomendacion'][4]
sen_cust = df_oct_2019.groupby('Franquicia').sum()['Recomendacion'][5]
# Franchise customer Pie chart
fran = ['<NAME>, Qro.', 
        '<NAME>, Qro.', 
       'Juriquilla, Qro.',
       '<NAME>.',
       '<NAME>, Qro.',
       'Sendero, Qro.']
customer_quan = [ber_cust, jar_cust, jur_cust, ln_cust, sjr_cust, sen_cust] 
colors = ['#00A0B0','#6A4A3C', '#CC333F', '#EB6841', '#EDC951', '#CC333F']

plt.figure(figsize=(10,8))
plt.pie(customer_quan, labels=fran, colors=colors, shadow=True, autopct='%1.1f%%')

plt.title('October Customer Distribution')
plt.show()

for i in range(0, len(customer_quan)):
    print(f'{fran[i]}: {customer_quan[i]}')<jupyter_output><empty_output><jupyter_text>2. Recommendation rate<jupyter_code># Recomendation Histogram
recom = np.array(df_oct_2019['Recomendacion'])
bins = list(range(2, 12, 1))

plt.figure(figsize=(16,7))
plt.hist(recom, bins, histtype='bar', rwidth=0.8, color='#00A0B0')

plt.title('Recomendation Histogram')
plt.ylabel('Frequency')
plt.xlabel('Average')
plt.grid(linewidth =0.5, linestyle='--')
plt.axvline(np.mean(recom), color='red', linestyle='--', label='Mean')
plt.axvline(np.mean(recom) + np.std(recom), color='green', linestyle='--', label='+1 std')
plt.axvline(np.mean(recom) - np.std(recom), color='green', linestyle='--', label='-1 std')

plt.legend(loc='best')
plt.show()

df_oct_2019['Recomendacion'].describe()<jupyter_output><empty_output><jupyter_text>According with the Empirical Rule, Rock n Ribs has 68% of his opinion range into a 8 to 10 average. This is a good average, but we need to know why the other customers rated us so low.<jupyter_code>df_oct_2019[df_oct_2019['Recomendacion']<8].groupby('Franquicia').sum()['Recomendacion']
df_oct_2019.groupby('Franquicia').sum()['Recomendacion']
# Low recomendation rate per Franchise
lowrec_ber = df_oct_2019[df_oct_2019['Recomendacion']<8].groupby('Franquicia').sum()['Recomendacion'][0]
lowrec_jar = df_oct_2019[df_oct_2019['Recomendacion']<8].groupby('Franquicia').sum()['Recomendacion'][1]
lowrec_jur = df_oct_2019[df_oct_2019['Recomendacion']<8].groupby('Franquicia').sum()['Recomendacion'][2]
lowrec_ln = df_oct_2019[df_oct_2019['Recomendacion']<8].groupby('Franquicia').sum()['Recomendacion'][3]
lowrec_sjr = df_oct_2019[df_oct_2019['Recomendacion']<8].groupby('Franquicia').sum()['Recomendacion'][4]
lowrec_sen = df_oct_2019[df_oct_2019['Recomendacion']<8].groupby('Franquicia').sum()['Recomendacion'][5]

total_ber = df_oct_2019.groupby('Franquicia').sum()['Recomendacion'][0]
total_jar = df_oct_2019.groupby('Franquicia').sum()['Recomendacion'][1]
total_jur = df_oct_2019.groupby('Franquicia').sum()['Recomendacion'][2]
total_ln = df_oct_2019.groupby('Franquicia').sum()['Recomendacion'][3]
total_sjr = df_oct_2019.groupby('Franquicia').sum()['Recomendacion'][4]
total_sen = df_oct_2019.groupby('Franquicia').sum()['Recomendacion'][5]

lowrate_ber = lowrec_ber/total_ber
lowrate_jar = lowrec_jar/total_jar
lowrate_jur = lowrec_jur/total_jur
lowrate_ln = lowrec_ln/total_ln
lowrate_sjr = lowrec_sjr/total_sjr
lowrate_sen = lowrec_sen/total_sen


# Configuring a bar graph
x = ['BQ', 'JAR', 'JUR', 'LN', 'SJR', 'SEN']
y = [lowrate_ber, lowrate_jar, lowrate_jur, lowrate_ln, lowrate_sjr, lowrate_sen]

plt.figure(figsize=(16,8))
plt.bar(x, y, width=0.8, color=colors)

plt.title('Ratio de No Recomendación')
plt.ylabel('Porcentaje')

plt.show()

for i in range(0, len(x)):
    print(f'{x[i]} : {round(y[i],4)}')<jupyter_output><empty_output><jupyter_text>We can look that <NAME> and León franchises have worst recomendation rates, in spite of the mayority bad recomendations come from Sendero. So we must analyze the comments existing.<jupyter_code>df_oct_2019[df_oct_2019['Recomendacion']<8].groupby('Franquicia')['Comentarios'].count()
coms = list(df_oct_2019[df_oct_2019['Recomendacion']<8].groupby('Franquicia')['Comentarios'])
bad_com_dict = {}
for i in range(0, len(coms)):
    bad_com_dict[f'{coms[i][0]}'] = coms[i][1]
# No recomendation comments from <NAME>
for i in list(bad_com_dict['B<NAME>ana, Qro.'].keys()):
    print(bad_com_dict['Bernardo Quintana, Qro.'][i])
# No recomendation comments from Jardines de la Hacienda
for i in list(bad_com_dict['Jardines de la Hacienda, Qro.'].keys()):
    print(bad_com_dict['Jardines de la Hacienda, Qro.'][i])
# No recomendation comments from León
for i in list(bad_com_dict['León, Gto.'].keys()):
    print(bad_com_dict['León, Gto.'][i])
# No recomendation comments from Sendero
for i in list(bad_com_dict['Sendero, Qro.'].keys()):
    print(bad_com_dict['Sendero, Qro.'][i])<jupyter_output>Deberían considerar agregar alguna salsa o picante adicional a los platillos        
Mejorar el servicio pues es muy lento
No
Ninguno
Ninguna, todo BN.
No
Ninguna me parece buen lugar
Tardan un poco más en preparae la comida que su competecia
El tiempo de espera en los alimentos es demasiado largo al igual que la toma de orden 
No
La carne de la hamburguesa ticket no tiene buen sabor
No vamos a regresar
nan
No
Buen ambiente
No<jupyter_text><NAME>1. Mesas suciasJardines de la Hacienda1. <NAME> no compensó la falla2. Ha bajado la calidad de carne para hamburguesa (2x)León1. Salsas de las alas muy saladas2. Costra de las alas muy gruesa3. Mejoren la calidad de la carneSendero1. Agregar salsa picantes2. Servicio muy lento (3x) 3. Food and Drink Average<jupyter_code># Total Average Food Count
df_food_ = list(df_oct_2019['Comida'])
total_e_f = 0
total_b_f = 0
total_r_f = 0
total_m_f = 0
total_na_f = 0

for i in df_food_:
    if i == 'Excelente':
        total_e_f += 1
    elif i == 'Bueno':
        total_b_f += 1
    elif i == 'Regular':
        total_r_f += 1
    elif i == 'Malo':
        total_m_f += 1
    else:
        total_na_f += 1
        
# Total Average Drink Count
df_drink_ = list(df_oct_2019['Bebida'])
total_e_d = 0
total_b_d = 0
total_r_d = 0
total_m_d = 0
total_na_d = 0

for i in df_drink_:
    if i == 'Excelente':
        total_e_d += 1
    elif i == 'Bueno':
        total_b_d += 1
    elif i == 'Regular':
        total_r_d += 1
    elif i == 'Malo':
        total_m_d += 1
    else:
        total_na_d += 1
        
# Congigure the graph bar
plt.figure(figsize=(16,5))
avg = ['Excelente', 'Bueno', 'Regular', 'Malo']
food_list = [total_e_f, total_b_f, total_r_f, total_m_f]
drink_list = [total_e_d, total_b_d, total_r_d, total_m_d]

plt.bar(avg, food_list, label='Comida', width=0.8, color = '#CC333F')
plt.bar(avg, drink_list, label='Bebida', width=0.8, color = '#00A0B0', bottom = food_list)

plt.title('Evaluación de Comida y Bebida')
plt.ylabel('Clientes')

plt.legend(loc='best')
plt.show()<jupyter_output><empty_output><jupyter_text>This month was very positive in terms of food and drink average. Only we need to look if REGULAR or MALO averages provided from all franchises (uniform distribution) or provided from few locals.<jupyter_code># Bad rate from Food per Franchise
df_food_outna = df_oct_2019[['Franquicia', 'Comida']].dropna()
df_food_res = df_food_outna[(df_food_outna['Comida'] == 'Regular') | (df_food_outna['Comida'] == 'Malo')].groupby('Franquicia').count()
df_food_res['Total'] = [
    df_food_outna.groupby('Franquicia').count()['Comida'][0],
    df_food_outna.groupby('Franquicia').count()['Comida'][1],
    df_food_outna.groupby('Franquicia').count()['Comida'][3],
    df_food_outna.groupby('Franquicia').count()['Comida'][5]
    ]
df_food_res

df_food_res['Rate'] = [
    df_food_res['Comida'][0]/df_food_outna.groupby('Franquicia').count()['Comida'][0],
    df_food_res['Comida'][1]/df_food_outna.groupby('Franquicia').count()['Comida'][1],
    df_food_res['Comida'][2]/df_food_outna.groupby('Franquicia').count()['Comida'][3],
    df_food_res['Comida'][3]/df_food_outna.groupby('Franquicia').count()['Comida'][5]
]
df_food_res
# Configuring a bar graph
x_1 = ['BQ', 'JAR', 'LN', 'SEN']
y_1 = list(df_food_res['Rate'])

plt.figure(figsize=(16,8))
plt.bar(x_1, y_1, width=0.8, color=colors)

plt.title('Ratio de Disguto por Comida')
plt.ylabel('Porcentaje')

plt.show()

for i in range(0, len(x_1)):
    print(f'{x_1[i]} : {round(y_1[i],4)}')<jupyter_output><empty_output><jupyter_text>After normalizing the graph according with their total customers who answer this part of the survey, we can note yet that food in León on october 2019 was the worst of all. And if we take a look to customer comments, the events relationate as well. Virtually Leon and Sendero franchise comments<jupyter_code># Bad comments from León Franchise
for i in list(bad_com_dict['León, Gto.'].keys()):
    print(bad_com_dict['León, Gto.'][i])
# Bad comments from Sendero Franchise
for i in list(bad_com_dict['Sendero, Qro.'].keys()):
    print(bad_com_dict['Sendero, Qro.'][i])<jupyter_output>Deberían considerar agregar alguna salsa o picante adicional a los platillos        
Mejorar el servicio pues es muy lento
No
Ninguno
Ninguna, todo BN.
No
Ninguna me parece buen lugar
Tardan un poco más en preparae la comida que su competecia
El tiempo de espera en los alimentos es demasiado largo al igual que la toma de orden 
No
La carne de la hamburguesa ticket no tiene buen sabor
No vamos a regresar
nan
No
Buen ambiente
No<jupyter_text>Other thing that could be important to highlight is that <NAME> has a hight no recomendation rate but also has a lower bad rate about food. So this could be indicate that customers were disgusted with the service more than the food quality.<jupyter_code># Bad rate from Drink per Franchise
df_drink_outna = df_oct_2019[['Franquicia', 'Bebida']].dropna()
df_drink_res = df_drink_outna[(df_drink_outna['Bebida'] == 'Regular') | (df_drink_outna['Bebida'] == 'Malo')].groupby('Franquicia').count()
df_drink_res['Total'] = [
    df_drink_outna.groupby('Franquicia').count()['Bebida'][0],
    df_drink_outna.groupby('Franquicia').count()['Bebida'][2],
    df_drink_outna.groupby('Franquicia').count()['Bebida'][3],
    df_drink_outna.groupby('Franquicia').count()['Bebida'][4],
    df_drink_outna.groupby('Franquicia').count()['Bebida'][5]
    ]
df_drink_res

df_drink_res['Rate'] = [
    df_drink_res['Bebida'][0]/df_drink_outna.groupby('Franquicia').count()['Bebida'][0],
    df_drink_res['Bebida'][1]/df_drink_outna.groupby('Franquicia').count()['Bebida'][2],
    df_drink_res['Bebida'][2]/df_drink_outna.groupby('Franquicia').count()['Bebida'][3],
    df_drink_res['Bebida'][3]/df_drink_outna.groupby('Franquicia').count()['Bebida'][4],
    df_drink_res['Bebida'][4]/df_drink_outna.groupby('Franquicia').count()['Bebida'][5]
]
df_drink_res
# Configuring a bar graph
x_2 = ['BQ', 'JUR', 'LN', 'SJR', 'SEN']
y_2 = list(df_drink_res['Rate'])

plt.figure(figsize=(16,8))
plt.bar(x_2, y_2, width=0.8, color=colors)

plt.title('Ratio de Disguto por Bebida')
plt.ylabel('Porcentaje')

plt.show()

for i in range(0, len(x_2)):
    print(f'{x_2[i]} : {round(y_2[i],4)}')
#Visualizing in one graph to compare food vs drink dislike
y_1 = list(df_food_res['Rate'])
y_1.insert(2,0.0)
y_1.insert(4,0.0)

y_2_pos = list(df_drink_res['Rate'])
y_2_pos.insert(1,0.0)

y_2 = []
for i in y_2_pos:
    y_2.append(i*(-1))

x_3 = ['BQ', 'JAR', 'JUR', 'LN', 'SJR', 'SEN']

# Configuring a bar graph
plt.figure(figsize=(16,8))
plt.bar(x_3, y_1, facecolor=colors[0], edgecolor='white', label='Comida')
plt.bar(x_3, y_2, facecolor=colors[3], edgecolor='white', label='Bebida')

for x, y in zip(x_3, y_1):
    plt.text(x, y + 0.005, '%.2f' % y, ha='center', va= 'bottom')
for x, y in zip(x_3, y_2):
    plt.text(x, y - 0.018, '%.2f' % y, ha='center', va= 'bottom')

plt.xlim(-.5, 5.5)
plt.ylim(-0.25, 0.25)
plt.legend(loc='best')
plt.title('Ratio de Disgusto General')

plt.show()<jupyter_output><empty_output><jupyter_text>I conclude that <NAME> and Sendero must be append on yellow light list, but correction on food of Leon franchise is most relevant, because its averages are very lower.  4. Price-Quality rate<jupyter_code>df_pq_outna = df_oct_2019[['Franquicia', 'CalidadPrecio']].dropna()

# Bernardo Quintana Price-Quality Rate
pq_bq_sum = df_pq_outna[df_pq_outna['Franquicia']=='Bernardo Quintana, Qro.'].groupby('CalidadPrecio').count()

# Jardines de la Hacienda Price-Quality Rate
pq_jh_sum = df_pq_outna[df_pq_outna['Franquicia']=='Jardines de la Hacienda, Qro.'].groupby('CalidadPrecio').count()

# Juriquilla Price-Quality Rate
pq_jur_sum = df_pq_outna[df_pq_outna['Franquicia']=='Juriquilla, Qro.'].groupby('CalidadPrecio').count()

# León Price-Quality Rate
pq_ln_sum = df_pq_outna[df_pq_outna['Franquicia']=='León, Gto.'].groupby('CalidadPrecio').count()

# San Juan del Río Price-Quality Rate
pq_sjr_sum = df_pq_outna[df_pq_outna['Franquicia']=='San Juan del Río, Qro.'].groupby('CalidadPrecio').count()

# Sendero Price-Quality Rate
pq_sen_sum = df_pq_outna[df_pq_outna['Franquicia']=='Sendero, Qro.'].groupby('CalidadPrecio').count()
# Price-Quality Rate per Franchise
plt.figure(figsize=(16,8))

plt.subplot(2,3,1)
plt.pie(list(pq_bq_sum['Franquicia']), labels=list(pq_bq_sum['Franquicia'].keys()), colors=colors, shadow=True, autopct='%1.1f%%')
plt.title('<NAME>')

plt.subplot(2,3,2)
plt.pie(list(pq_jh_sum['Franquicia']), labels=list(pq_jh_sum['Franquicia'].keys()), colors=colors, shadow=True, autopct='%1.1f%%')
plt.title('Jardines de la Hacienda')

plt.subplot(2,3,3)
plt.pie(list(pq_jur_sum['Franquicia']), labels=list(pq_jur_sum['Franquicia'].keys()), colors=colors, shadow=True, autopct='%1.1f%%')
plt.title('Juriquilla')

plt.subplot(2,3,4)
plt.pie(list(pq_ln_sum['Franquicia']), labels=list(pq_ln_sum['Franquicia'].keys()), colors=colors, shadow=True, autopct='%1.1f%%')
plt.title('León')

plt.subplot(2,3,5)
plt.pie(list(pq_sjr_sum['Franquicia']), labels=list(pq_sjr_sum['Franquicia'].keys()), colors=colors, shadow=True, autopct='%1.1f%%')
plt.title('San Juan del Río')

plt.subplot(2,3,6)
plt.pie(list(pq_sen_sum['Franquicia']), labels=list(pq_sen_sum['Franquicia'].keys()), colors=colors, shadow=True, autopct='%1.1f%%')
plt.title('Sendero')

plt.show()<jupyter_output><empty_output><jupyter_text>This metric is very dinamic month a month because the Management Team of Rock n Ribs change his prices of each franchise according to the season, the existing inventory or other events like soccer matchs with the aim to increase his revenue. Looking this graphs we can perceive that Juriquilla and León have the best scores to Price-Quality Rate, maybe because the mean cost of food in there cities is higher than the others franchise cities. With the aim to clarify this hipothesys we take a look into https://www.inegi.org.mx/app/preciospromedio/ to understand the cost of food in these states.<jupyter_code># Download our dataset from INEGI.ORG.MX 
df_cost_food = pd.read_csv('./INP_PP.csv')
df_cost_food[0:5]
# Filtering according with supplies needed for cooking Rock n Ribs dishes
df_cost_food[(df_cost_food['Generico']=='Pan de caja') | 
(df_cost_food['Generico']=='Carne de res') |
(df_cost_food['Generico']=='Carne de cerdo') |
(df_cost_food['Generico']=='Pollo') |
(df_cost_food['Generico']=='Tocino') |
(df_cost_food['Generico']=='Cerveza') |
(df_cost_food['Generico']=='Ron') |
(df_cost_food['Generico']=='Masa y harinas de maíz') |
(df_cost_food['Generico']=='Masa y harinas de maíz')].groupby('Nombre ciudad').describe()['Precio promedio']<jupyter_output><empty_output><jupyter_text>Unfortunately does not exist crearly information about cost of food per each township, so we can get data only from principal cities on our states. Even so, we look that the diference in prices between both cities is not relevant. Possibly we could develop other analysis about our providers prices to compare with others. Also we could scrapping the costs of our restaurant rivals. 5. Client Retention<jupyter_code># We take Recomendacion column like a reference to count easily without NaN values
df_be_cust = pd.DataFrame(df_oct_2019[['Franquicia','TiempoSerCliente','Recomendacion']].groupby(['Franquicia', 'TiempoSerCliente']).count())
df_be_cust
keys_be_cust = list(df_be_cust['Recomendacion'].keys())

params_dict = {}
for i in range(0, len(keys_be_cust)-1):
    params_dict[f'{keys_be_cust[i][0]} , {keys_be_cust[i][1]}'] = df_be_cust['Recomendacion'][keys_be_cust[i][0]][keys_be_cust[i][1]]
y_bq = [params_dict['<NAME>, Qro. , Esta es mi primera\xa0visita'], 
        params_dict['<NAME>, Qro. , Seis meses a un año'],
        params_dict['<NAME>, Qro. , 1-2 años'],
        params_dict['<NAME>, Qro. , 3 años o más']]
        
y_jh = [params_dict['Jardines de la Hacienda, Qro. , Esta es mi primera\xa0visita'], 
        params_dict['Jardines de la Hacienda, Qro. , Seis meses a un año'],
        params_dict['Jardines de la Hacienda, Qro. , 1-2 años'],
        params_dict['Jardines de la Hacienda, Qro. , 3 años o más']]
        
y_jur = [params_dict['Jardines de la Hacienda, Qro. , Esta es mi primera\xa0visita'], 
        params_dict['Jardines de la Hacienda, Qro. , Seis meses a un año'],
        params_dict['Jardines de la Hacienda, Qro. , 1-2 años'],
        params_dict['Jardines de la Hacienda, Qro. , 3 años o más']]

y_ln = [params_dict['León, Gto. , Esta es mi primera\xa0visita'], 
        params_dict['León, Gto. , Seis meses a un año'],
        params_dict['León, Gto. , 1-2 años'],
        0]

y_sjr = [params_dict['San Juan del Río, Qro. , Esta es mi primera\xa0visita'], 
        params_dict['San Juan del Río, Qro. , Seis meses a un año'],
        params_dict['San Juan del Río, Qro. , 1-2 años'],
        params_dict['San Juan del Río, Qro. , 3 años o más']]

y_sen = [params_dict['Sendero, Qro. , Esta es mi primera\xa0visita'], 
        0,
        params_dict['Sendero, Qro. , 1-2 años'],
        params_dict['Sendero, Qro. , 3 años o más']]
# Design the graph bar
x = ['1st visit', '6m to 1y', '1y to 2y', '3y +']

plt.figure(figsize=(16,5))
plt.plot(x, y_bq, label='<NAME>', linewidth=2, color=colors[0])
plt.plot(x, y_jh, label='J<NAME>enda', linewidth=2, color=colors[1])
plt.plot(x, y_jur, label='Juriquilla', linewidth=2, color='k')
plt.plot(x, y_ln, label='León', linewidth=2, color=colors[3])
plt.plot(x, y_sjr, label='San J<NAME> Río', linewidth=2, color=colors[4])
plt.plot(x, y_sen, label='Sendero', linewidth=2, color=colors[5])

plt.gca().invert_xaxis()
plt.title('Retención de los Clientes')
plt.xlabel = ('Tiempo de Ser Cliente')
plt.ylabel = ('Clientes')
plt.grid(linewidth=0.8, linestyle=':')
plt.legend(loc='best')

plt.show()<jupyter_output><empty_output><jupyter_text>Most customer quantity came from Sendero, in specific the customers whose first visit was 1 year to back. Sendero and León had an increment for new clients on October, but the other franchises had a decrease on this topic. The customer retention in general is uniform but partly decreasing, with an exception in Sendero, which retention was been very changeable, in this case we need to look up other retention rate months to have a best look for this event. 6. Advertising media effectiveness<jupyter_code>df_oct_2019.columns
# Firstly we must to analyze if comments about Other Media Ways are relevant
df_oct_2019['OtroMedCon'].dropna()<jupyter_output><empty_output><jupyter_text>Live or work near to Rock n Ribs restaurants is not relevant; we assume this fact yet. The other comments could group on Recomendation subgroup. The most important comment is from friend of workers, is important because we can create comercial strategies to attract these potential clients.<jupyter_code>df_medcon_outna = df_oct_2019[['Franquicia','MedCon', 'Recomendacion']].dropna()
df_medcon_outna.groupby(['Franquicia', 'MedCon']).count()
df_medcon_outna.groupby(['Franquicia', 'MedCon']).count()['Recomendacion']['<NAME>, Qro.']['Lo ví']
keys_list_medcon = list(df_medcon_outna.groupby(['Franquicia', 'MedCon']).count()['Recomendacion'].keys())
medcon_dict = {}
for key in keys_list_medcon:
    medcon_dict[f'{key[0]},{key[1]}'] = df_medcon_outna.groupby(['Franquicia', 'MedCon']).count()['Recomendacion'][key[0]][key[1]]
bq_watch = medcon_dict['<NAME>, Qro.,Lo ví']
bq_adv = medcon_dict['<NAME>, Qro.,Publicidad']
bq_rec = medcon_dict['<NAME>, Qro.,Recomendación']
bq_sm = medcon_dict['<NAME>, Qro.,Redes sociales (facebook, twitter, instagram)']
bq_medcon_list = [bq_watch, bq_adv, bq_rec, bq_sm]

jh_watch = medcon_dict['Jardines de la Hacienda, Qro.,Lo ví']
jh_adv = medcon_dict['Jardines de la Hacienda, Qro.,Publicidad']
jh_rec = medcon_dict['Jardines de la Hacienda, Qro.,Recomendación']
jh_sm = medcon_dict['Jardines de la Hacienda, Qro.,Redes sociales (facebook, twitter, instagram)']
jh_medcon_list = [jh_watch, jh_adv, jh_rec, jh_sm]

jur_watch = medcon_dict['Juriquilla, Qro.,Lo ví']
jur_rec = medcon_dict['Juriquilla, Qro.,Recomendación']
jur_sm = medcon_dict['Juriquilla, Qro.,Redes sociales (facebook, twitter, instagram)']
jur_medcon_list = [jur_watch, jur_rec, jur_sm]

ln_watch = medcon_dict['León, Gto.,Lo ví']
ln_adv = medcon_dict['León, Gto.,Publicidad']
ln_rec = medcon_dict['León, Gto.,Recomendación']
ln_sm = medcon_dict['León, Gto.,Redes sociales (facebook, twitter, instagram)']
ln_medcon_list = [ln_watch, ln_adv, ln_rec, ln_sm]

sjr_watch = medcon_dict['San Juan del Río, Qro.,Lo ví']
sjr_adv = medcon_dict['San Juan del Río, Qro.,Publicidad']
sjr_rec = medcon_dict['San Juan del Río, Qro.,Recomendación']
sjr_sm = medcon_dict['San Juan del Río, Qro.,Redes sociales (facebook, twitter, instagram)']
sjr_medcon_list = [sjr_watch, sjr_adv, sjr_rec, sjr_sm]

sen_watch = medcon_dict['Sendero, Qro.,Lo ví']
sen_adv = medcon_dict['Sendero, Qro.,Publicidad']
sen_rec = medcon_dict['Sendero, Qro.,Recomendación']
sen_sm = medcon_dict['Sendero, Qro.,Redes sociales (facebook, twitter, instagram)']
sen_web = medcon_dict['<NAME>.,Página web']
sen_medcon_list = [sen_watch, sen_adv, sen_rec, sen_sm, sen_web]
# Customer way to knew Rock n Ribs
plt.figure(figsize=(16,8))

plt.subplot(2,3,1)
plt.pie(bq_medcon_list , labels=['Lo ví', 'Publicidad', 'Recomendación', 'Social Media'], colors=colors, shadow=True, autopct='%1.1f%%')
plt.title('<NAME>')

plt.subplot(2,3,2)
plt.pie(jh_medcon_list , labels=['Lo ví', 'Publicidad', 'Recomendación', 'Social Media'], colors=colors, shadow=True, autopct='%1.1f%%')
plt.title('Jardines de la Hacienda')

plt.subplot(2,3,3)
plt.pie(jur_medcon_list , labels=['Lo ví', 'Recomendación', 'Social Media'], colors=colors, shadow=True, autopct='%1.1f%%')
plt.title('Juriquilla')

plt.subplot(2,3,4)
plt.pie(ln_medcon_list , labels=['Lo ví', 'Publicidad', 'Recomendación', 'Social Media'], colors=colors, shadow=True, autopct='%1.1f%%')
plt.title('León')

plt.subplot(2,3,5)
plt.pie(sjr_medcon_list , labels=['Lo ví', 'Publicidad', 'Recomendación', 'Social Media'], colors=colors, shadow=True, autopct='%1.1f%%')
plt.title('San Juan del Río')

plt.subplot(2,3,6)
plt.pie(sen_medcon_list , labels=['Lo ví', 'Publicidad', 'Recomendación', 'Social Media', 'Web'], colors=colors, shadow=True, autopct='%1.1f%%')
plt.title('Sendero')

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15725743653636506, 'fraction_numerical': 0.02935679800654104, 'mean_word_length': 6.280328798185941, 'pattern_counts': {'":': 0, '<': 100, '<?xml version=': 0, '>': 91, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '14763', 'license': 'MIT', 'n_tokens_mistral': 10498, 'n_tokens_neox': 9899, 'n_words': 2162, 'path': 'rnr_survey_improvement_analysis.ipynb', 'repo_name': 'axelrocha-py/rnr_surveys_analysis', 'size': '25949'}