Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/KevinOrtiz/An-lisis-Explo…
- Loading branch information
Showing
8 changed files
with
177 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
__author__ = 'josanvel' | ||
|
||
import pandas as pd | ||
import numpy as np | ||
from pandas import Series | ||
|
||
def add_category_actividades(): | ||
actiidades = pd.read_csv("../data/TripAdvisor/nuevo_data_actividades.csv") | ||
|
||
#Convierto los datos de los rating a FLOAT | ||
actiidades['rating'] = actiidades['rating'].astype(float) | ||
actiidades['category'] = actiidades['rating'].map(lambda x: 'Excelente' if (x > 4 and x <= 5) | ||
else 'Bueno' if (x > 2 and x <= 4) | ||
else 'Regular') | ||
#Guardo el dataframe de actividades en un nuevo archivo CSV | ||
actiidades.to_csv('../data/TripAdvisor/data_actividades_categorizado.csv') | ||
|
||
if __name__ == '__main__': | ||
add_category_actividades() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
__author__ = 'josanvel' | ||
|
||
import json | ||
import csv | ||
import string | ||
|
||
def get_fields_json(): | ||
#Abro el archivo JSON de las Actividades | ||
with open('scrapy_hotel/scrapy_hotel/spiders/data_actividades_tag.json') as data_file: | ||
data_json = json.load(data_file) | ||
|
||
#Creo el archivo CSV | ||
csv_file = open('../data/TripAdvisor/nuevo_data_actividades.csv', 'w') | ||
#Creo la cabecera del CSV | ||
cabecera_json = 'name,longitude,latitude,rating,NoReviews,tags\n' | ||
#Guardo la cabecera en el archivo CSV | ||
csv_file.write(cabecera_json) | ||
|
||
for element in data_json: | ||
#Obtengo la ubicacion del Hotel en cooredenadas | ||
location = element['location'] | ||
lng = location[0] | ||
lat = location[1] | ||
|
||
if not (lng is None and lat is None): | ||
name = element['name'] #Obtengo el nombre de la Actividad | ||
name = string.replace(name, ',', '') | ||
rating = element['rating'] #Obtengo el raiting de la Actividad | ||
reviews = element['reviews'] #Obtengo los reviews de la Actividad | ||
NoReviews = len(reviews) #Obtengo el numoero de reviews de la Actividad | ||
tags = element['tag'] #Obtengo los tags de la Actividad | ||
|
||
line_tags = "" | ||
for tag in tags: | ||
line_tags = line_tags+'$'+tag #Obtengo TODOS los tags de la Actividad $aaaaa$ggggg$ooooo | ||
|
||
#Concateno la linea del CSV | ||
line = str(name)+','+str(lng)+','+str(lat)+','+str(rating)+','+str(NoReviews)+','+line_tags+'\n' | ||
#Guardo la linea en el archivo CSV | ||
if rating: | ||
csv_file.write(line) | ||
|
||
if __name__ == '__main__': | ||
get_fields_json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
__author__ = 'josanvel' | ||
|
||
import json | ||
import csv | ||
import string | ||
|
||
def get_fields_json(): | ||
#Abro el archivo JSON de los hoteles | ||
with open('scrapy_hotel/scrapy_hotel/spiders/data_hotel_completo.json') as data_file: | ||
data_json = json.load(data_file) | ||
|
||
#Creo el archivo CSV | ||
csv_file = open('../data/TripAdvisor/nuevo_data_hotel.csv', 'w') | ||
#Creo la cabecera del CSV | ||
cabecera_json = 'name,longitude,latitude,rating,NoReviews\n' | ||
#Guardo la cabecera en el archivo CSV | ||
csv_file.write(cabecera_json) | ||
|
||
for element in data_json: | ||
#Obtengo la ubicacion del Hotel en cooredenadas | ||
location = element['location'] | ||
lng = location[0] | ||
lat = location[1] | ||
|
||
if not (lng is None and lat is None): | ||
name = element['name'] #Obtengo el nombre de un hotel | ||
name = string.replace(name, ',', '') | ||
rating = element['rating'] #Obtengo el raiting de un hotel | ||
reviews = element['reviews'] #Obtengo los reviews de un hotel | ||
NoReviews = len(reviews) #Obtengo el numoero de reviews de un hotel | ||
|
||
#Concateno la linea del CSV | ||
line = str(name)+','+str(lng)+','+str(lat)+','+str(rating)+','+str(NoReviews)+'\n' | ||
#Guardo la linea en el archivo CSV | ||
if rating: | ||
csv_file.write(line) | ||
|
||
if __name__ == '__main__': | ||
get_fields_json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
__author__ = 'josanvel' | ||
|
||
import pandas as pd | ||
import numpy as np | ||
from pandas import Series | ||
|
||
def add_category_hotels(): | ||
hotels = pd.read_csv("../data/TripAdvisor/nuevo_data_hotel.csv") | ||
|
||
#Convierto los datos de los rating a FLOAT | ||
hotels['rating'] = hotels['rating'].astype(float) | ||
hotels['category'] = hotels['rating'].map(lambda x: 'Excelente' if (x > 4 and x <= 5) | ||
else 'Bueno' if (x > 2 and x <= 4) | ||
else 'Regular') | ||
#Guardo el dataframe de actividades en un nuevo archivo CSV | ||
hotels.to_csv('../data/TripAdvisor/data_hotel_categorizado.csv') | ||
|
||
if __name__ == '__main__': | ||
add_category_hotels() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.