Skip to content

Instantly share code, notes, and snippets.

@iangelmx
Last active June 1, 2020 03:04
Show Gist options
  • Save iangelmx/da92cb1287af668942fd87e5a0bc63cb to your computer and use it in GitHub Desktop.
Save iangelmx/da92cb1287af668942fd87e5a0bc63cb to your computer and use it in GitHub Desktop.
# Hacemos que la columna Entity sea un índice
f_2 = filtered.set_index('Entity')
# Volvemos a filtrar, pero ahora los países potencia junto con México
power_countries = f_2.loc[ ['Mexico', 'United States' ,
'United Kingdom', 'Russia',
'South Korea'] ]
#Creamos una Pivot table que sume todas las pruebas de cada país
table = pd.pivot_table(
power_countries,
values = 'New tests',
index = ['Entity'],
aggfunc=sum,
fill_value=0
).sort_values(by='New tests', ascending=True)
#Cambiamos el nombre de la columna New test a Pruebas
table = table.rename(columns={ 'New tests':'Pruebas' })
table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment