Created
February 7, 2026 18:52
-
-
Save robintux/12c8bff07970d1e8b6ce117a79b91b06 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # Modulos y datos | |
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| import seaborn as sns | |
| import numpy as np | |
| uber = pd.read_csv("https://raw.githubusercontent.com/robintux/Datasets4StackOverFlowQuestions/refs/heads/master/Datos_Uber_2024.csv") | |
| # Preprocesamiento | |
| uber['Date'] = pd.to_datetime(uber['Date'], format='%Y-%m-%d') | |
| uber['Year'] = uber['Date'].dt.year | |
| uber['Month'] = uber['Date'].dt.month | |
| uber['MonthName'] = uber['Date'].dt.month_name() | |
| uber['DayOfWeek'] = uber['Date'].dt.dayofweek # 0 = lunes, 6 = domingo | |
| uber['DayName'] = uber['Date'].dt.day_name() | |
| uber['WeekOfYear'] = uber['Date'].dt.isocalendar().week | |
| uber['Time'] = pd.to_datetime(uber['Time'], format='%H:%M:%S').dt.time | |
| uber['Datetime'] = pd.to_datetime(uber['Date'].astype(str) + ' ' + uber['Time'].astype(str)) | |
| # Extraer hora del día como entero (0 a 23) | |
| uber['Hour'] = uber['Datetime'].dt.hour | |
| # Categorizar horas del día (opcional) | |
| def hora_bloque(h): | |
| if 5 <= h < 9: return 'Mañana (5-9)' | |
| elif 9 <= h < 13: return 'Media mañana (9-13)' | |
| elif 13 <= h < 17: return 'Tarde (13-17)' | |
| elif 17 <= h < 21: return 'Pico (17-21)' | |
| elif 21 <= h < 24: return 'Noche (21-24)' | |
| else: return 'Madrugada (0-5)' | |
| uber['HourBlock'] = uber['Hour'].apply(hora_bloque) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment