('π΅πΉ', 'π΅πΉ')
Flags
Get the flag emoji of a country using its 2 (or 3)-letter ISO country code
flag
flag (cc)
Get the flag emoji of a country using its 2 (or three)-letter code.
Type | Details | |
---|---|---|
cc | str | Country code, a string of two letters |
Returns | str | The Unicode emoji flag of the respective country |
Get some country flags
('π―π΅', 'π―π΅', 'π―π΅', 'π―π΅', 'π―π΅')
Use in a Jupyter notebook
The following html
and md
functions enable HTML and markdown output to contain dynamic values.
Use in a markdown string
Use in an HTML string for more granular control
Using flags in Plotly charts
population = pd.DataFrame({
'country': ['China', 'India', 'United States', 'Indonesia', 'Pakistan'],
'population': [1439323776, 1380004385, 331002651, 273523615, 220892340],
'code': ['cn', 'in', 'us', 'id', 'pk']
})
population
country | population | code | |
---|---|---|---|
0 | China | 1439323776 | cn |
1 | India | 1380004385 | in |
2 | United States | 331002651 | us |
3 | Indonesia | 273523615 | id |
4 | Pakistan | 220892340 | pk |
fig = px.bar(
population,
x='country',
y='population',
height=500,
text=[flag(cc) for cc in population['code']],
template='ggplot2'
)
fig.data[0].textfont.size = 35
fig.data[0].marker.color = 'steelblue'
fig
fig = px.bar(
population.sort_values('population'),
y='country',
x='population',
orientation='h',
height=500,
opacity=0.8,
text=[flag(cc) for cc in population.sort_values('population')['code']],
template='ggplot2'
)
fig.data[0].textfont.size = 35
fig.data[0].marker.color = 'teal'
fig
europe = gapminder().query('year==2007').query('continent=="Europe"')
europe['flag'] = [flag(cc) for cc in europe['iso_alpha']]
europe.head()
country | continent | year | lifeExp | pop | gdpPercap | iso_alpha | iso_num | flag | |
---|---|---|---|---|---|---|---|---|---|
23 | Albania | Europe | 2007 | 76.423 | 3600523 | 5937.029526 | ALB | 8 | π¦π± |
83 | Austria | Europe | 2007 | 79.829 | 8199783 | 36126.492700 | AUT | 40 | π¦πΉ |
119 | Belgium | Europe | 2007 | 79.441 | 10392226 | 33692.605080 | BEL | 56 | π§πͺ |
155 | Bosnia and Herzegovina | Europe | 2007 | 74.852 | 4552198 | 7446.298803 | BIH | 70 | π§π¦ |
191 | Bulgaria | Europe | 2007 | 73.005 | 7322858 | 10680.792820 | BGR | 100 | π§π¬ |
fig = px.scatter(
europe,
x='gdpPercap',
y='lifeExp',
height=600,
text='flag',
hover_data=['lifeExp', 'pop','gdpPercap'],
hover_name=europe['flag'].add(' ').add(europe['country']),
title=f'Life expectancy ~ GDP per capita<br><b>Europe 2007</b>',
template='plotly_white',
log_y=False)
fig.data[0].textfont.size = 35
fig.data[0].hoverlabel.bgcolor = 'white'
fig.data[0].hoverlabel.font.size = 20
fig