<jupyter_start><jupyter_text>Hace falta algo que indique con qué entorno vamos a trabajar Importar lo que hace falta<jupyter_code>import pandas as pd
import numpy as np
import seaborn as sns
import re
data_url = "../Data/properatti.csv"
data = pd.read_csv(data_url, encoding="utf-8")
#limpiamos los que NaN en el precio
data = data.dropna(axis=0, how='any', subset=['price_aprox_usd'])
#funcion para borrar outliers.
def borrar_outliers(data, columnas):
    """Solo recibo columnas con valores numericos. 
    Las columns van en forma de tupla"""
    cols_limpiar = columnas
    mask=np.ones(shape=(data.shape[0]), dtype=bool)

    for i in cols_limpiar:
        
        #calculamos cuartiles, y valores de corte
        Q1=data[i].quantile(0.25)
        Q3=data[i].quantile(0.75)
        RSI=Q3-Q1
        max_value=Q3+1.5*RSI
        min_value=Q1-1.5*RSI
        
        #ajusto el min value a mano... no puede ser negativo.
        min_value=10
        
        #filtramos por max y min
        mask=np.logical_and(mask, np.logical_and(data[i]>=min_value, data[i]<=max_value))
    return data[mask]
def regex_to_bool(col, reg) :
    u"""Returns a series with boolean mask result of apply the regular expresion to the column
    col : column where to apply regular expresion
    reg : regular expresion compiled
    """
    
    serie = col.apply(lambda x : x if x is np.NaN else reg.search(x))
    serie = serie.apply(lambda x : x is not None)
   
    return serie
def regex_to_ones(col, reg, fill = 0) :
    u"""Returns a series with ones or other value result of apply the regular expresion to the column
    the value of one will be when the regular expression search() method found a match
    the fill value (default to 0) will be when the regular expression serach() method did not found a match
    col : column where to apply regular expresion
    reg : regular expresion compiled
    """
    
    serie = col.apply(lambda x : x if x is np.NaN else reg.search(x))
    serie = serie.apply(lambda x : 1 if x is not None else fill)
   
    return serie
_pattern = 'cochera|garage|auto'
_express = re.compile(_pattern, flags = re.IGNORECASE)

work = regex_to_ones(data['description'], _express)
data['cochera'] = work
_pattern = 'piscina|pileta'
_express = re.compile(_pattern, flags = re.IGNORECASE)

work = regex_to_ones(data['description'], _express)
data['pileta'] = work
_pattern = 'parrilla'
_express = re.compile(_pattern, flags = re.IGNORECASE)

work = regex_to_ones(data['description'], _express)
data['parrilla'] = work
_pattern = 'balcon'
_express = re.compile(_pattern, flags = re.IGNORECASE)

work = regex_to_ones(data['description'], _express)
data['balcon'] = work
# Crear una categoría númerica (en base 2) de acuerdo a los valores individuales (es dependiente de la posición)

data['amenities'] = data['cochera']*8 + data['pileta']*4 + data['parrilla']*2 + data['balcon']
data[['cochera', 'pileta', 'parrilla', 'balcon', 'amenities']]
data['amenities'].describe()
data['amenities'].value_counts()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11173001310615989, 'fraction_numerical': 0.009174311926605505, 'mean_word_length': 3.869218500797448, 'pattern_counts': {'":': 0, '<': 6, '<?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': '100347', 'license': 'CC0-1.0', 'n_tokens_mistral': 1047, 'n_tokens_neox': 1031, 'n_words': 317, 'path': 'Notebooks/TP1.POC/TP1.reg2.ipynb', 'repo_name': 'jtentor/DHDSPW1', 'size': '3052'}