Objetivo

Python


import pandas as pd
import os

os.getcwd()
## 'C:\\Users\\consultor01\\Desktop\\R+Python'
fifa = pd.read_csv('fifa_ranking.csv')
fifa.head()

# Seleccionando a Peru y Chile
##    rank country_full  ... confederation   rank_date
## 0     1      Germany  ...          UEFA  1993-08-08
## 1     2        Italy  ...          UEFA  1993-08-08
## 2     3  Switzerland  ...          UEFA  1993-08-08
## 3     4       Sweden  ...          UEFA  1993-08-08
## 4     5    Argentina  ...      CONMEBOL  1993-08-08
## 
## [5 rows x 16 columns]
fifa = fifa[(fifa['country_abrv'] == 'PER')|(fifa['country_abrv'] == 'CHI')]
fifa.head()

# ... con total_points > 0
##      rank country_full  ... confederation   rank_date
## 48     49        Chile  ...      CONMEBOL  1993-08-08
## 69     70         Peru  ...      CONMEBOL  1993-08-08
## 218    52        Chile  ...      CONMEBOL  1993-09-23
## 239    73         Peru  ...      CONMEBOL  1993-09-23
## 385    52        Chile  ...      CONMEBOL  1993-10-22
## 
## [5 rows x 16 columns]
fifa = fifa[fifa.total_points > 0]
fifa.describe()

# considerar solo las columnas rank, country_abrv, total_points, rank_change, cur_year_avg, 
# last_year_avg, rank_date
##              rank  total_points  ...  three_year_ago_avg  three_year_ago_weighted
## count  166.000000    166.000000  ...          166.000000               166.000000
## mean    23.614458    928.766386  ...          396.037048                79.207289
## std     16.389820    247.555503  ...          140.252879                28.050459
## min      3.000000    486.820000  ...           68.420000                13.680000
## 25%     11.000000    703.145000  ...          257.802500                51.560000
## 50%     16.000000    965.370000  ...          418.865000                83.775000
## 75%     36.750000   1124.925000  ...          488.625000                97.727500
## max     64.000000   1422.140000  ...          673.710000               134.740000
## 
## [8 rows x 12 columns]
fifa = fifa[['rank', 'country_abrv', 'total_points', 'rank_change',
               'cur_year_avg', 'last_year_avg', 'rank_date']]
fifa.head()
##        rank country_abrv  total_points  ...  cur_year_avg  last_year_avg   rank_date
## 40389    11          CHI        959.85  ...        447.07         572.30  2011-08-24
## 40404    26          PER        805.72  ...        448.07         550.70  2011-08-24
## 40598    14          CHI        932.15  ...        417.26         586.12  2011-09-21
## 40619    35          PER        723.80  ...        422.61         420.24  2011-09-21
## 40807    16          CHI        941.48  ...        459.03         472.01  2011-10-19
## 
## [5 rows x 7 columns]

R

# Visualizar la tendencia del puntaje Fifa de Perú

library(ggplot2)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
g = ggplot(py$fifa, aes(x=rank_date, y=total_points, group=country_abrv,color=country_abrv)) + geom_point() + geom_line(aes(color=country_abrv))+
  theme(axis.text.x = element_text(angle = 90, hjust = 1),legend.position = "top")

ggplotly(g)