Análisis de ventas de videojuegos con python
Proyecto final de módulo de Python - BEDU
Presentado por: Daniel Carmona
Para el proyecto final, se utilizo la base de datos de Video Game Sales y multiple data source
Este conjunto de datos contiene una lista de videojuegos con ventas superiores a 100.000 copias. Fue
generado por un raspado de vgchartz.com.
Los campos incluyen:
- Clasificación: clasificación de las ventas generales
- Nombre: el nombre del juego
- Plataforma: plataforma del lanzamiento del juego (es decir, PC, PS4, etc.)
- Año: año de lanzamiento del juego
- Género: género del juego
- Editor: editor del juego
- NA_Sales - Ventas en Norteamérica (en millones)
- EU_Sales - Ventas en Europa (en millones)
- JP_Sales - Ventas en Japón (en millones)
- Other_Sales - Ventas en el resto del mundo (en millones)
- Global_Sales: ventas mundiales totales.
Tabla de contenido
- Librerias
- Lectura de conjuntos
- Visualización del Dataframe
- Normalizar los DataFrames
- Uniendo los dataframes con pd.concat()
- Descripción de los datos con info() y describre()
- Limpieza y tranformación de valores
- Aplicando Apply
- Analizando la data
1. Librerias
import
pandas as
pd
2. Lectura del conjunto de datos
Vemos las dimensiones del dataframe
3. Visualización del Dataframe
print
(df_games.head(3))# | Rank | Name | Platform | Year | Genre | Publisher | NA_Sales | EU_Sales | JP_Sales | Other_Sales | Global_Sales |
---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | Wii Sports | Wii | 2006.0 | Sports | Nintendo | 41.49 | 29.02 | 3.77 | 8.46 | 82.74 |
1 | 2 | Super Mario Bros. | NES | 1985.0 | Platform | Nintendo | 29.08 | 3.58 | 6.81 | 0.77 | 40.24 |
2 | 3 | Mario Kart Wii | Wii | 2008.0 | Racing | Nintendo | 15.85 | 12.88 | 3.79 | 3.31 | 35.82 |
print
(df_ps4.head(3))# | Game | Year | Genre | Publisher | North America | Europe | Japan | Rest of World | Global |
---|---|---|---|---|---|---|---|---|---|
0 | Grand Theft Auto V | 2014.0 | Action | Rockstar Games | 6.06 | 9.71 | 0.60 | 3.02 | 19.39 |
1 | Call of Duty: Black Ops 3 | 2015.0 | Shooter | Activision | 6.18 | 6.05 | 0.41 | 2.44 | 15.09 |
2 | Red Dead Redemption 2 | 2018.0 | Action-Adventure | Rockstar Games | 5.26 | 6.21 | 0.21 | 2.26 | 13.94 |
print
(df_xboxone.head(3))# | Pos | Game | Year | Genre | Publisher | North America | Europe | Japan | Rest of World | Global |
---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | Grand Theft Auto V | 2014.0 | Action | Rockstar Games | 4.70 | 3.25 | 0.01 | 0.76 | 8.72 |
1 | 2 | Call of Duty: Black Ops 3 | 2015.0 | Shooter | Activision | 4.63 | 2.04 | 0.02 | 0.68 | 7.37 |
2 | 3 | Call of Duty: WWII | 2017.0 | Shooter | Activision | 3.75 | 1.91 | 0.00 | 0.57 | 6.23 |
4. Normalizar los DataFrames
Se crea una nueva columna a los DataFrames de PS4 y XboxOne y se le agrega su respectiva plataforma.
print
(df_ps4.head(3))# | Game | Platform | Year | Genre | Publisher | North America | Europe | Japan | Rest of World | Global |
---|---|---|---|---|---|---|---|---|---|---|
0 | Grand Theft Auto V | PS4 | 2014.0 | Action | Rockstar Games | 6.06 | 9.71 | 0.60 | 3.02 | 19.39 |
1 | Call of Duty: Black Ops 3 | PS4 | 2015.0 | Shooter | Activision | 6.18 | 6.05 | 0.41 | 2.44 | 15.09 |
2 | Red Dead Redemption 2 | PS4 | 2018.0 | Action-Adventure | Rockstar Games | 5.26 | 6.21 | 0.21 | 2.26 | 13.94 |
Se eliminaran las columnas 'Rank' y 'Pos'para poder unir de forma efectiva los 3 dataframes
# | Game | Year | Genre | Publisher | North America | Europe | Japan | Rest of World | Global |
---|---|---|---|---|---|---|---|---|---|
0 | Grand Theft Auto V | 2014.0 | Action | Rockstar Games | 4.70 | 3.25 | 0.01 | 0.76 | 8.72 |
1 | Call of Duty: Black Ops 3 | 2015.0 | Shooter | Activision | 4.63 | 2.04 | 0.02 | 0.68 | 7.37 |
2 | Call of Duty: WWII | 2017.0 | Shooter | Activision | 3.75 | 1.91 | 0.00 | 0.57 | 6.23 |
Renombrando columnas de df_games2 para que sean las mismas de PS4 y XboxOne
# | Game | Platform | Year | Genre | Publisher | North America | Europe | Japan | Rest of World | Global |
---|---|---|---|---|---|---|---|---|---|---|
0 | Wii Sports | Wii | 2006.0 | Sports | Nintendo | 41.49 | 29.02 | 3.77 | 8.46 | 82.74 |
1 | Super Mario Bros. | NES | 1985.0 | Platform | Nintendo | 29.08 | 3.58 | 6.81 | 0.77 | 40.24 |
5. Uniendo los dataframes con pd.concat()
Uniremos los 3 DataFrames ahora que tienen la misma cantidad columnas y mismos nombres de columnas
# | Game | Platform | Year | Genre | Publisher | North America | Europe | Japan | Rest of World | Global |
---|---|---|---|---|---|---|---|---|---|---|
0 | Wii Sports | Wii | 2006.0 | Sports | Nintendo | 41.49 | 29.02 | 3.77 | 8.46 | 82.74 |
1 | Super Mario Bros. | NES | 1985.0 | Platform | Nintendo | 29.08 | 3.58 | 6.81 | 0.77 | 40.24 |
2 | Mario Kart Wii | Wii | 2008.0 | Racing | Nintendo | 15.85 | 12.88 | 3.79 | 3.31 | 35.82 |
Cambiamos encabezados
# | Nombre | Plataforma | Anio_lanzamiento | Genero | Empresa | NorteAmerica | Europa | Japon | Resto_del_Mundo | Global |
---|---|---|---|---|---|---|---|---|---|---|
0 | Wii Sports | Wii | 2006.0 | Sports | Nintendo | 41.49 | 29.02 | 3.77 | 8.46 | 82.74 |
1 | Super Mario Bros. | NES | 1985.0 | Platform | Nintendo | 29.08 | 3.58 | 6.81 | 0.77 | 40.24 |
2 | Mario Kart Wii | Wii | 2008.0 | Racing | Nintendo | 15.85 | 12.88 | 3.79 | 3.31 | 35.82 |
6. Descripcción de los datos con info() y describre()
# | NorteAmerica | Europa | Japon | Resto_del_Mundo | Global |
---|---|---|---|---|---|
count | 17621.000000 | 17621.000000 | 17621.000000 | 17621.000000 | 17621.000000 |
mean | 0.266835 | 0.155775 | 0.074881 | 0.051384 | 0.549131 |
std | 0.809443 | 0.529187 | 0.301364 | 0.193330 | 1.564241 |
min | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 |
25% | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.060000 |
50% | 0.080000 | 0.020000 | 0.000000 | 0.010000 | 0.170000 |
75% | 0.240000 | 0.110000 | 0.030000 | 0.040000 | 0.480000 |
max | 41.490000 | 29.020000 | 10.220000 | 10.570000 | 82.740000 |
<class 'pandas.core.frame.DataFrame'> Int64Index: 18245 entries, 0 to 612 Data columns (total 10 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Game 18245 non-null object 1 Platform 18245 non-null object 2 Year 17657 non-null float64 3 Genre 18245 non-null object 4 Publisher 17870 non-null object 5 North America 18245 non-null float64 6 Europe 18245 non-null float64 7 Japan 18245 non-null float64 8 Rest of World 18245 non-null float64 9 Global 18245 non-null float64 dtypes: float64(6), object(4) memory usage: 1.5+ MB
7. Limpieza y tranformación de valores
Veremos cuantos elementos NA tenemos en el DataFrame
sum
()Nombre 0 Plataforma 0 Anio_lanzamiento 588 Genero 0 Empresa 375 NorteAmerica 0 Europa 0 Japon 0 Resto_del_Mundo 0 Global 0 dtype: int64
sum
()Nombre 0 Plataforma 0 Anio_lanzamiento 0 Genero 0 Empresa 0 NorteAmerica 0 Europa 0 Japon 0 Resto_del_Mundo 0 Global 0 dtype: int64
Reseteamos los indices ya que se eliminaron filas
Ahora si tenemos que cambiar los valores a su tipo de dato que corresponden
Nombre object
Plataforma object
Anio_lanzamiento float64
Genero object
Empresa object
NorteAmerica float64
Europa float64
Japon float64
Resto_del_Mundo float64
Global float64
dtype: object
Cambiamos 'Anio_lanzamiento a valor de fecha
0 2006-01-01 1 1985-01-01 2 2008-01-01 3 2009-01-01 4 1996-01-01 ... 17616 2018-01-01 17617 2019-01-01 17618 2017-01-01 17619 2017-01-01 17620 2019-01-01 Name: Anio_lanzamiento, Length: 17621, dtype: datetime64[ns]
8. Aplicando Apply
Creamos la función que aplicaremos al DataFrame
def print_row(value): print(value) print("------------------------------")df.iloc[0:3].apply(print_row, axis=1)
Nombre Wii Sports Plataforma Wii Anio_lanzamiento 2006-01-01 00:00:00 Genero Sports Empresa Nintendo NorteAmerica 41.49 Europa 29.02 Japon 3.77 Resto_del_Mundo 8.46 Global 82.74 Name: 0, dtype: object ------------------------------ Nombre Super Mario Bros. Plataforma NES Anio_lanzamiento 1985-01-01 00:00:00 Genero Platform Empresa Nintendo NorteAmerica 29.08 Europa 3.58 Japon 6.81 Resto_del_Mundo 0.77 Global 40.24 Name: 1, dtype: object ------------------------------ Nombre Mario Kart Wii Plataforma Wii Anio_lanzamiento 2008-01-01 00:00:00 Genero Racing Empresa Nintendo NorteAmerica 15.85 Europa 12.88 Japon 3.79 Resto_del_Mundo 3.31 Global 35.82 Name: 2, dtype: object ------------------------------ 0 None 1 None 2 None dtype: object
9. Analizando la data
Asignamos a variables significativas, los valores que se enceuntran en las columnas 'Nombre','Plataforma','Genero' y 'Empresa'
Imprimos cada variable de forma ordenada
sorted
(plataformas)sorted
(Generos)print
(f'Descripción: \n')
print
(f'---------------------------------------\n')
print
(f'{("Cantidad de juegos"):29} | {len
(juegos):9}')
print
(f'{("Plataformas de Videojuegos"):29} | {len
(plataformas):9}')
print
(f'{("Total de generos"):29} | {len
(generos):9}')
print
(f'{("Total de desarrolladoras"):29} | {len
(empresas):9}')Descripción: --------------------------------------- Cantidad de juegos | 11804 Plataformas de Videojuegos | 31 Total de generos | 17 Total de desarrolladoras | 649
9.1 Genéros más populares
Action 3573 Sports 2431 Misc 1771 Role-Playing 1613 Shooter 1423 Adventure 1381 Racing 1318 Platform 926 Simulation 888 Fighting 884 Strategy 709 Puzzle 585 Action-Adventure 66 Music 31 Visual Novel 10 MMO 10 Party 2 Name: Genero, dtype: int64
9.2 ¿Cuantas copias a vendido el genero acción?
sum
().sort_values(ascending=False)Genero Action 1910.17 Sports 1444.52 Shooter 1253.40 Role-Playing 1002.62 Platform 849.55 Misc 811.23 Racing 770.02 Fighting 469.71 Simulation 397.00 Adventure 254.63 Puzzle 242.96 Strategy 175.48 Action-Adventure 79.33 Music 9.44 MMO 5.04 Party 0.65 Visual Novel 0.48 Name: Global, dtype: float64
sum
().sort_values(ascending=False)[0]
print(f"El genero Action ha vendido un total de {int(cantidad_ventas_genero)} millones de copias" )9.3 ¿Cuál fue el año que más juegos se publicaron?
2009-01-01 1431 2008-01-01 1428 2010-01-01 1257 2007-01-01 1201 2011-01-01 1136 2006-01-01 1008 2005-01-01 936 2015-01-01 895 2002-01-01 829 2003-01-01 775 2014-01-01 755 ...... Name: Anio_lanzamiento, dtype: int64
9.4 ¿Cuantós juegos con la palabra WII existen?
cantidad_wii = df[df['Nombre'].str.startswith('Wii')].shape print(f'Hay un total de {cantidad_wii[0]} juegos con la palabra WII\n') for game in df[df['Nombre'].str.startswith('Wii')].Nombre.to_list(): print(game)
9.5 Los 10 videojuegos más viejos
# | Nombre | Platforma | Anio_lanzamiento | Genero | Empresa | NorteAmerica | Europa | Japon | Resto_del_Mundo | Global |
---|---|---|---|---|---|---|---|---|---|---|
0 | Checkers | 2600 | 1980-01-01 | Misc | Atari | 0.22 | 0.01 | 0.0 | 0.00 | 0.24 |
1 | Kaboom! | 2600 | 1980-01-01 | Misc | Activision | 1.07 | 0.07 | 0.0 | 0.01 | 1.15 |
2 | Freeway | 2600 | 1980-01-01 | Action | Activision | 0.32 | 0.02 | 0.0 | 0.00 | 0.34 |
3 | Defender | 2600 | 1980-01-01 | Misc | Atari | 0.99 | 0.05 | 0.0 | 0.01 | 1.05 |
4 | Asteroids | 2600 | 1980-01-01 | Shooter | Atari | 4.00 | 0.26 | 0.0 | 0.05 | 4.31 |
5 | Boxing | 2600 | 1980-01-01 | Fighting | Activision | 0.72 | 0.04 | 0.0 | 0.01 | 0.77 |
6 | Missile Command | 2600 | 1980-01-01 | Shooter | Atari | 2.56 | 0.17 | 0.0 | 0.03 | 2.76 |
7 | Bridge | 2600 | 1980-01-01 | Misc | Activision | 0.25 | 0.02 | 0.0 | 0.00 | 0.27 |
8 | Ice Hockey | 2600 | 1980-01-01 | Sports | Activision | 0.46 | 0.03 | 0.0 | 0.01 | 0.49 |
9 | Astroblast | 2600 | 1981-01-01 | Action | Mattel Interactive | 0.29 | 0.02 | 0.0 | 0.00 | 0.31 |
9.6 ¿Qué plataforma tiene más juegos?
9.7 ¿Qué plataforma ha vendido más copias?
9.8 ¿Qué empresa ha vendido más copias?
9.9 ¿Cuantas copias ha vendido cada una de las consolas de la empresa Nintento?
Plataforma 3DS 156.45 DS 349.10 GB 229.06 GBA 112.00 GC 79.15 N64 129.62 NES 183.97 SNES 96.84 Wii 390.34 WiiU 57.90 Name: Global, dtype: float64
suma = 0 for e in copias_nintendo: suma = suma + e print(f'La suma de las copias vendidas de cada una de las consolas de la empresa Nintendo da un total de {int(suma)} millones de copias vendidas')
9.10 ¿Cuál es el videojuego más vendido de cada plataforma?
Plataforma Nombre Global Wii Wii Sports 82.74 NES Super Mario Bros. 40.24 GB Pokemon Red/Pokemon Blue 31.37 DS New Super Mario Bros. 30.01 X360 Kinect Adventures! 21.82 PS3 Grand Theft Auto V 21.40 PS2 Grand Theft Auto: San Andreas 20.81 SNES Super Mario World 20.61 PS4 Grand Theft Auto V 19.39 GBA Pokemon Ruby/Pokemon Sapphire 15.85 3DS Pokemon X/Pokemon Y 14.35 N64 Super Mario 64 11.89 PS Gran Turismo 10.95 XOne Grand Theft Auto V 8.72 XB Halo 2 8.49 PC The Sims 3 8.11 2600 Pac-Man 7.81 PSP Grand Theft Auto: Liberty City Stories 7.72 GC Super Smash Bros. Melee 7.07 WiiU Mario Kart 8 6.96 GEN Sonic the Hedgehog 2 6.03 DC Sonic Adventure 2.42 PSV Minecraft 2.25 SAT Virtua Fighter 2 1.93 SCD Sonic CD 1.50 WS Final Fantasy 0.51 NG Samurai Shodown II 0.25 TG16 Doukyuusei 0.14 3DO Policenauts 0.06 GG Sonic the Hedgehog 2 (8-bit) 0.04 PCFX Blue Breaker: Ken Yorimo Hohoemi o 0.03
9.11 ¿Cuales han sido los mejores juegos por cada año que más a vendido Nintendo?
Anio_lanzamiento Nombre Global 2006 Wii Sports 82.74 1985 Super Mario Bros. 40.24 2008 Mario Kart Wii 35.82 2009 Wii Sports Resort 33.00 1996 Pokemon Red/Pokemon Blue 31.37 1989 Tetris 30.26 1984 Duck Hunt 28.31 2005 Nintendogs 24.76 1999 Pokemon Gold/Pokemon Silver 23.10 2007 Wii Fit 22.72 1990 Super Mario World 20.61 1988 Super Mario Bros. 3 17.28 2002 Pokemon Ruby/Pokemon Sapphire 15.85 2010 Pokemon Black/Pokemon White 15.32 1998 Pokémon Yellow: Special Pikachu Edition 14.64 2013 Pokemon X/Pokemon Y 14.35 2011 Mario Kart 7 12.21 2014 Pokemon Omega Ruby/Pokemon Alpha Sapphire 11.33 1992 Super Mario Land 2: 6 Golden Coins 11.18 1993 Super Mario All-Stars 10.55 2004 Pokemon FireRed/Pokemon LeafGreen 10.49 2012 New Super Mario Bros. 2 9.82 1994 Donkey Kong Country 9.30 1997 GoldenEye 007 8.09 2001 Super Smash Bros. Melee 7.07 2003 Mario Kart: Double Dash!! 6.95 1986 The Legend of Zelda 6.51 2000 Pokémon Crystal Version 6.39 1995 Donkey Kong Country 2: Diddy's Kong Quest 5.15 1991 The Legend of Zelda: A Link to the Past 4.61 2015 Splatoon 4.57 1987 Zelda II: The Adventure of Link 4.38 1983 Baseball 3.20 2016 The Legend of Zelda: Twilight Princess HD 0.94
9.12 ¿Qué genero se vende más en Norte America, Europa, Japón y Resto del mundo?
# | Action | Action -Adventure | Adventure | Fighting | MMO | Misc | Music | Party | Platform | Puzzle | Racing | Role-Playing | Shooter | Simulation | Sports | Strategy | Visual Novel |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
NorteAmerica | 940.48 | 32.73 | 109.88 | 233.72 | 2.27 | 405.80 | 5.58 | 0.09 | 453.00 | 122.45 | 371.29 | 358.55 | 683.00 | 184.77 | 729.01 | 69.08 | 0.20 |
Europa | 589.22 | 33.28 | 71.52 | 107.41 | 1.87 | 220.65 | 2.40 | 0.47 | 210.37 | 50.72 | 258.99 | 214.65 | 395.27 | 115.79 | 427.06 | 45.23 | 0.02 |
Japon | 169.00 | 1.97 | 53.66 | 88.83 | 0.20 | 107.64 | 0.17 | 0.00 | 131.32 | 56.68 | 57.46 | 359.66 | 42.80 | 63.82 | 136.61 | 49.44 | 0.21 |
Resto_del_Mundo | 210.26 | 11.41 | 19.35 | 39.75 | 0.69 | 76.57 | 1.27 | 0.10 | 54.53 | 12.60 | 82.01 | 69.75 | 131.90 | 32.29 | 151.41 | 11.49 | 0.05 |
1
)NorteAmerica 940.48 Action Europa 589.22 Action Japon 359.66 Role-Playing Resto_del_Mundo 210.26 Action dtype: float64
# | Action | Action -Adventure | Adventure | Fighting | MMO | Misc | Music | Party | Platform | Puzzle | Racing | Role-Playing | Shooter | Simulation | Sports | Strategy | Visual Novel |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
NorteAmerica | 940.48 | 32.73 | 109.88 | 233.72 | 2.27 | 405.80 | 5.58 | 0.09 | 453.00 | 122.45 | 371.29 | 358.55 | 683.00 | 184.77 | 729.01 | 69.08 | 0.20 |
Europa | 589.22 | 33.28 | 71.52 | 107.41 | 1.87 | 220.65 | 2.40 | 0.47 | 210.37 | 50.72 | 258.99 | 214.65 | 395.27 | 115.79 | 427.06 | 45.23 | 0.02 |
Japon | 169.00 | 1.97 | 53.66 | 88.83 | 0.20 | 107.64 | 0.17 | 0.00 | 131.32 | 56.68 | 57.46 | 359.66 | 42.80 | 63.82 | 136.61 | 49.44 | 0.21 |
Resto_del_Mundo | 210.26 | 11.41 | 19.35 | 39.75 | 0.69 | 76.57 | 1.27 | 0.10 | 54.53 | 12.60 | 82.01 | 69.75 | 131.90 | 32.29 | 151.41 | 11.49 | 0.05 |