SlideShare a Scribd company logo
1 of 3
Download to read offline
What is wrong with this code?
def plotCountryDensities(data: pd.DataFrame, title: str):
global inf
"""Visa stapeldiagram av lnders populationstthet.
Args:
data (pd.DataFrame): land data
"""
# Figur.
fig, ax = plt.subplots()
# Plotta data.
ax = data.plot.bar(
ax=ax,
rot=40,
x='country',
y='density')
ax.get_legend().remove()
# Titlar.
plt.title(title, color='b')
plt.xlabel('Countries', color='r')
plt.ylabel('Population density as persons/sqkm.', color='r')
# A4, liggande.
fig.set_size_inches(11.69, 8.27)
# Visa.
plt.grid()
plt.show()
def assignment_2_menu(data: pd.DataFrame) -> None:
"""Plotta populationsttheten fr vald antal lnder
eller om landdet anges mend namn, skriv ut landets
populationstthet.
Args:
data (pd.DataFrame): land data
"""
# Instruktion.
print('''
Specify country/countries to show. Format: NAME | N[+|-]
NAME = Name of country
N = Integer between 1 and 10
+ = Whow N densest countries
- = Show N sparsest countries.''')
# Loopa tills vi ftt rtt input.
while True:
# Ls in anvndarval.
inputValue = input(" : ")
# Testa med regex om anvndaren angav nummer.
mo = re.match(r'^([0-9]{1,2})(+|-)?$', inputValue)
# Har vi match object?
if mo:
# Ls nummer och eventuell postfix.
num_countries = int(mo.group(1))
sort_type = mo.group(2)
# Kolla att vi har nummer mellan 1 och 10.
if 1 <= num_countries <= 10:
if sort_type:
# Vi har sortering. Sortera.
ascending_ = sort_type == '-'
subset = data.sort_values(
by=['density'],
ascending=ascending_
).head(num_countries)
side = 'lowest' if ascending_ else 'highest'
title = f'{num_countries} countries with the {side} population density.'
else:
subset = data.head(num_countries)
title = f'Population density for first {num_countries} countries.'
# Plotta de 'num_countries' lnder vi har i subset.
plotCountryDensities(subset, title)
break
else:
# Anvndaren angav inte nummer i rtt format.
# Testa om strngen matchar land.
inputValue = inputValue.replace('"', '')
searchResult = data.query(f'country=="{inputValue}"')
if not searchResult.empty:
# Rad hittades.
print(f'''
----------
The population density for {inputValue} is {searchResult.iloc[0].density:.2f} individuals per square
km.
----------
''')
break
print('Invalid input.')
# Titel
print('nTask 2 - Plotn')
# Skapa DataFrame objekt frn csv fil.
df_cia_factbook = pd.read_csv('cia_factbook.csv', delimiter=';')
# Berkna densitet fr alla rader och ta bort nan/inf rader.
modified = df_cia_factbook.eval(
'density = population / area'
).query(
'density == density and density != @inf'
)
# Visa-lnder meny.
assignment_2_menu(modified)
Task2-Plot NameError: name 're' is not defined

More Related Content

Similar to What is wrong with this code def plotCountryDensitiesdata.pdf

ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions Dr. Volkan OBAN
 
The Web map stack on Django
The Web map stack on DjangoThe Web map stack on Django
The Web map stack on DjangoPaul Smith
 
Python Pandas for Data Science cheatsheet
Python Pandas for Data Science cheatsheet Python Pandas for Data Science cheatsheet
Python Pandas for Data Science cheatsheet Dr. Volkan OBAN
 
Feature-Engineering-Earth-Advocacy-Project-2015
Feature-Engineering-Earth-Advocacy-Project-2015Feature-Engineering-Earth-Advocacy-Project-2015
Feature-Engineering-Earth-Advocacy-Project-2015Ankoor Bhagat
 
Pandas pythonfordatascience
Pandas pythonfordatasciencePandas pythonfordatascience
Pandas pythonfordatascienceNishant Upadhyay
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..Kamarudheen KV
 
Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data Sciencehenrygarner
 
JavaScript в браузере: Web API (часть 1)
JavaScript в браузере: Web API (часть 1)JavaScript в браузере: Web API (часть 1)
JavaScript в браузере: Web API (часть 1)Timur Shemsedinov
 
A quick introduction to R
A quick introduction to RA quick introduction to R
A quick introduction to RAngshuman Saha
 
Income Qualification ppt.pptx
Income Qualification ppt.pptxIncome Qualification ppt.pptx
Income Qualification ppt.pptxShilpaSweety2
 

Similar to What is wrong with this code def plotCountryDensitiesdata.pdf (20)

Supstat nyc subway
Supstat nyc subwaySupstat nyc subway
Supstat nyc subway
 
ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions
 
Googlevis examples
Googlevis examplesGooglevis examples
Googlevis examples
 
The Web map stack on Django
The Web map stack on DjangoThe Web map stack on Django
The Web map stack on Django
 
Python Pandas for Data Science cheatsheet
Python Pandas for Data Science cheatsheet Python Pandas for Data Science cheatsheet
Python Pandas for Data Science cheatsheet
 
Py lecture5 python plots
Py lecture5 python plotsPy lecture5 python plots
Py lecture5 python plots
 
Feature-Engineering-Earth-Advocacy-Project-2015
Feature-Engineering-Earth-Advocacy-Project-2015Feature-Engineering-Earth-Advocacy-Project-2015
Feature-Engineering-Earth-Advocacy-Project-2015
 
Pandas pythonfordatascience
Pandas pythonfordatasciencePandas pythonfordatascience
Pandas pythonfordatascience
 
R Functions in Dataframe.pptx
R Functions in Dataframe.pptxR Functions in Dataframe.pptx
R Functions in Dataframe.pptx
 
Programming with matlab session 6
Programming with matlab session 6Programming with matlab session 6
Programming with matlab session 6
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..
 
2 pandasbasic
2 pandasbasic2 pandasbasic
2 pandasbasic
 
MatplotLib.pptx
MatplotLib.pptxMatplotLib.pptx
MatplotLib.pptx
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data Science
 
JavaScript в браузере: Web API (часть 1)
JavaScript в браузере: Web API (часть 1)JavaScript в браузере: Web API (часть 1)
JavaScript в браузере: Web API (часть 1)
 
R training5
R training5R training5
R training5
 
A Shiny Example-- R
A Shiny Example-- RA Shiny Example-- R
A Shiny Example-- R
 
A quick introduction to R
A quick introduction to RA quick introduction to R
A quick introduction to R
 
Income Qualification ppt.pptx
Income Qualification ppt.pptxIncome Qualification ppt.pptx
Income Qualification ppt.pptx
 

More from accumencomp

Are large firms such as Walmart and Microsoft good or bad fo.pdf
Are large firms such as Walmart and Microsoft good or bad fo.pdfAre large firms such as Walmart and Microsoft good or bad fo.pdf
Are large firms such as Walmart and Microsoft good or bad fo.pdfaccumencomp
 
6 The investigative process by which geologists identify an.pdf
6 The investigative process by which geologists identify an.pdf6 The investigative process by which geologists identify an.pdf
6 The investigative process by which geologists identify an.pdfaccumencomp
 
Aadakilerden hangisi biyolojik bir zarn bileenlerini bir ara.pdf
Aadakilerden hangisi biyolojik bir zarn bileenlerini bir ara.pdfAadakilerden hangisi biyolojik bir zarn bileenlerini bir ara.pdf
Aadakilerden hangisi biyolojik bir zarn bileenlerini bir ara.pdfaccumencomp
 
1 Faiz oran euro cinsinden varlklarda yzde 7 dolar cinsin.pdf
1 Faiz oran euro cinsinden varlklarda yzde 7 dolar cinsin.pdf1 Faiz oran euro cinsinden varlklarda yzde 7 dolar cinsin.pdf
1 Faiz oran euro cinsinden varlklarda yzde 7 dolar cinsin.pdfaccumencomp
 
Compute the following measures a Return on equity Net in.pdf
Compute the following measures a Return on equity  Net in.pdfCompute the following measures a Return on equity  Net in.pdf
Compute the following measures a Return on equity Net in.pdfaccumencomp
 
Consider a data of a numerical variable X given by the group.pdf
Consider a data of a numerical variable X given by the group.pdfConsider a data of a numerical variable X given by the group.pdf
Consider a data of a numerical variable X given by the group.pdfaccumencomp
 
Aada bahsedilen Vaka almasndan aadaki sorular cevaplayn Nes.pdf
Aada bahsedilen Vaka almasndan aadaki sorular cevaplayn Nes.pdfAada bahsedilen Vaka almasndan aadaki sorular cevaplayn Nes.pdf
Aada bahsedilen Vaka almasndan aadaki sorular cevaplayn Nes.pdfaccumencomp
 
3102 Protect and monitor the physical facility and support.pdf
3102 Protect and monitor the physical facility and support.pdf3102 Protect and monitor the physical facility and support.pdf
3102 Protect and monitor the physical facility and support.pdfaccumencomp
 
Match the following incubation periods with their function .pdf
Match the following incubation periods with their function .pdfMatch the following incubation periods with their function .pdf
Match the following incubation periods with their function .pdfaccumencomp
 
The US Census Bureau estimates that there will be approxim.pdf
The US Census Bureau estimates that there will be approxim.pdfThe US Census Bureau estimates that there will be approxim.pdf
The US Census Bureau estimates that there will be approxim.pdfaccumencomp
 
The following information is available for Oriole Corporatio.pdf
The following information is available for Oriole Corporatio.pdfThe following information is available for Oriole Corporatio.pdf
The following information is available for Oriole Corporatio.pdfaccumencomp
 
Santana Rey owner of Business Solutions decides to prepare.pdf
Santana Rey owner of Business Solutions decides to prepare.pdfSantana Rey owner of Business Solutions decides to prepare.pdf
Santana Rey owner of Business Solutions decides to prepare.pdfaccumencomp
 
QUESTION 4 Preduction data Poundt in proesss May 1 materi.pdf
QUESTION 4 Preduction data Poundt in proesss May 1 materi.pdfQUESTION 4 Preduction data Poundt in proesss May 1 materi.pdf
QUESTION 4 Preduction data Poundt in proesss May 1 materi.pdfaccumencomp
 
Python I keep running into error when fixing this code but.pdf
Python I keep running into error when fixing this code but.pdfPython I keep running into error when fixing this code but.pdf
Python I keep running into error when fixing this code but.pdfaccumencomp
 
Please answer ASAP Ill rate thanks 1 There are a total .pdf
Please answer ASAP Ill rate thanks 1 There are a total .pdfPlease answer ASAP Ill rate thanks 1 There are a total .pdf
Please answer ASAP Ill rate thanks 1 There are a total .pdfaccumencomp
 
ou are analyzing the Victoria Inc VI stock Assume that .pdf
ou are analyzing the Victoria Inc VI stock Assume that .pdfou are analyzing the Victoria Inc VI stock Assume that .pdf
ou are analyzing the Victoria Inc VI stock Assume that .pdfaccumencomp
 
n the very early days of computing images were produced usi.pdf
n the very early days of computing images were produced usi.pdfn the very early days of computing images were produced usi.pdf
n the very early days of computing images were produced usi.pdfaccumencomp
 
In 2020 Pina Corporation had pretax financial income of 16.pdf
In 2020 Pina Corporation had pretax financial income of 16.pdfIn 2020 Pina Corporation had pretax financial income of 16.pdf
In 2020 Pina Corporation had pretax financial income of 16.pdfaccumencomp
 
Instructions 1 Refer back to the video assignments present.pdf
Instructions 1 Refer back to the video assignments present.pdfInstructions 1 Refer back to the video assignments present.pdf
Instructions 1 Refer back to the video assignments present.pdfaccumencomp
 
Islandia lkesindeki iletmeler ulusal ekonomi hakknda karam.pdf
Islandia lkesindeki iletmeler ulusal ekonomi hakknda karam.pdfIslandia lkesindeki iletmeler ulusal ekonomi hakknda karam.pdf
Islandia lkesindeki iletmeler ulusal ekonomi hakknda karam.pdfaccumencomp
 

More from accumencomp (20)

Are large firms such as Walmart and Microsoft good or bad fo.pdf
Are large firms such as Walmart and Microsoft good or bad fo.pdfAre large firms such as Walmart and Microsoft good or bad fo.pdf
Are large firms such as Walmart and Microsoft good or bad fo.pdf
 
6 The investigative process by which geologists identify an.pdf
6 The investigative process by which geologists identify an.pdf6 The investigative process by which geologists identify an.pdf
6 The investigative process by which geologists identify an.pdf
 
Aadakilerden hangisi biyolojik bir zarn bileenlerini bir ara.pdf
Aadakilerden hangisi biyolojik bir zarn bileenlerini bir ara.pdfAadakilerden hangisi biyolojik bir zarn bileenlerini bir ara.pdf
Aadakilerden hangisi biyolojik bir zarn bileenlerini bir ara.pdf
 
1 Faiz oran euro cinsinden varlklarda yzde 7 dolar cinsin.pdf
1 Faiz oran euro cinsinden varlklarda yzde 7 dolar cinsin.pdf1 Faiz oran euro cinsinden varlklarda yzde 7 dolar cinsin.pdf
1 Faiz oran euro cinsinden varlklarda yzde 7 dolar cinsin.pdf
 
Compute the following measures a Return on equity Net in.pdf
Compute the following measures a Return on equity  Net in.pdfCompute the following measures a Return on equity  Net in.pdf
Compute the following measures a Return on equity Net in.pdf
 
Consider a data of a numerical variable X given by the group.pdf
Consider a data of a numerical variable X given by the group.pdfConsider a data of a numerical variable X given by the group.pdf
Consider a data of a numerical variable X given by the group.pdf
 
Aada bahsedilen Vaka almasndan aadaki sorular cevaplayn Nes.pdf
Aada bahsedilen Vaka almasndan aadaki sorular cevaplayn Nes.pdfAada bahsedilen Vaka almasndan aadaki sorular cevaplayn Nes.pdf
Aada bahsedilen Vaka almasndan aadaki sorular cevaplayn Nes.pdf
 
3102 Protect and monitor the physical facility and support.pdf
3102 Protect and monitor the physical facility and support.pdf3102 Protect and monitor the physical facility and support.pdf
3102 Protect and monitor the physical facility and support.pdf
 
Match the following incubation periods with their function .pdf
Match the following incubation periods with their function .pdfMatch the following incubation periods with their function .pdf
Match the following incubation periods with their function .pdf
 
The US Census Bureau estimates that there will be approxim.pdf
The US Census Bureau estimates that there will be approxim.pdfThe US Census Bureau estimates that there will be approxim.pdf
The US Census Bureau estimates that there will be approxim.pdf
 
The following information is available for Oriole Corporatio.pdf
The following information is available for Oriole Corporatio.pdfThe following information is available for Oriole Corporatio.pdf
The following information is available for Oriole Corporatio.pdf
 
Santana Rey owner of Business Solutions decides to prepare.pdf
Santana Rey owner of Business Solutions decides to prepare.pdfSantana Rey owner of Business Solutions decides to prepare.pdf
Santana Rey owner of Business Solutions decides to prepare.pdf
 
QUESTION 4 Preduction data Poundt in proesss May 1 materi.pdf
QUESTION 4 Preduction data Poundt in proesss May 1 materi.pdfQUESTION 4 Preduction data Poundt in proesss May 1 materi.pdf
QUESTION 4 Preduction data Poundt in proesss May 1 materi.pdf
 
Python I keep running into error when fixing this code but.pdf
Python I keep running into error when fixing this code but.pdfPython I keep running into error when fixing this code but.pdf
Python I keep running into error when fixing this code but.pdf
 
Please answer ASAP Ill rate thanks 1 There are a total .pdf
Please answer ASAP Ill rate thanks 1 There are a total .pdfPlease answer ASAP Ill rate thanks 1 There are a total .pdf
Please answer ASAP Ill rate thanks 1 There are a total .pdf
 
ou are analyzing the Victoria Inc VI stock Assume that .pdf
ou are analyzing the Victoria Inc VI stock Assume that .pdfou are analyzing the Victoria Inc VI stock Assume that .pdf
ou are analyzing the Victoria Inc VI stock Assume that .pdf
 
n the very early days of computing images were produced usi.pdf
n the very early days of computing images were produced usi.pdfn the very early days of computing images were produced usi.pdf
n the very early days of computing images were produced usi.pdf
 
In 2020 Pina Corporation had pretax financial income of 16.pdf
In 2020 Pina Corporation had pretax financial income of 16.pdfIn 2020 Pina Corporation had pretax financial income of 16.pdf
In 2020 Pina Corporation had pretax financial income of 16.pdf
 
Instructions 1 Refer back to the video assignments present.pdf
Instructions 1 Refer back to the video assignments present.pdfInstructions 1 Refer back to the video assignments present.pdf
Instructions 1 Refer back to the video assignments present.pdf
 
Islandia lkesindeki iletmeler ulusal ekonomi hakknda karam.pdf
Islandia lkesindeki iletmeler ulusal ekonomi hakknda karam.pdfIslandia lkesindeki iletmeler ulusal ekonomi hakknda karam.pdf
Islandia lkesindeki iletmeler ulusal ekonomi hakknda karam.pdf
 

Recently uploaded

DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 

Recently uploaded (20)

DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 

What is wrong with this code def plotCountryDensitiesdata.pdf

  • 1. What is wrong with this code? def plotCountryDensities(data: pd.DataFrame, title: str): global inf """Visa stapeldiagram av lnders populationstthet. Args: data (pd.DataFrame): land data """ # Figur. fig, ax = plt.subplots() # Plotta data. ax = data.plot.bar( ax=ax, rot=40, x='country', y='density') ax.get_legend().remove() # Titlar. plt.title(title, color='b') plt.xlabel('Countries', color='r') plt.ylabel('Population density as persons/sqkm.', color='r') # A4, liggande. fig.set_size_inches(11.69, 8.27) # Visa. plt.grid() plt.show() def assignment_2_menu(data: pd.DataFrame) -> None: """Plotta populationsttheten fr vald antal lnder eller om landdet anges mend namn, skriv ut landets populationstthet. Args: data (pd.DataFrame): land data """ # Instruktion. print(''' Specify country/countries to show. Format: NAME | N[+|-] NAME = Name of country N = Integer between 1 and 10 + = Whow N densest countries - = Show N sparsest countries.''') # Loopa tills vi ftt rtt input. while True: # Ls in anvndarval.
  • 2. inputValue = input(" : ") # Testa med regex om anvndaren angav nummer. mo = re.match(r'^([0-9]{1,2})(+|-)?$', inputValue) # Har vi match object? if mo: # Ls nummer och eventuell postfix. num_countries = int(mo.group(1)) sort_type = mo.group(2) # Kolla att vi har nummer mellan 1 och 10. if 1 <= num_countries <= 10: if sort_type: # Vi har sortering. Sortera. ascending_ = sort_type == '-' subset = data.sort_values( by=['density'], ascending=ascending_ ).head(num_countries) side = 'lowest' if ascending_ else 'highest' title = f'{num_countries} countries with the {side} population density.' else: subset = data.head(num_countries) title = f'Population density for first {num_countries} countries.' # Plotta de 'num_countries' lnder vi har i subset. plotCountryDensities(subset, title) break else: # Anvndaren angav inte nummer i rtt format. # Testa om strngen matchar land. inputValue = inputValue.replace('"', '') searchResult = data.query(f'country=="{inputValue}"') if not searchResult.empty: # Rad hittades. print(f''' ---------- The population density for {inputValue} is {searchResult.iloc[0].density:.2f} individuals per square km. ---------- ''') break print('Invalid input.') # Titel print('nTask 2 - Plotn')
  • 3. # Skapa DataFrame objekt frn csv fil. df_cia_factbook = pd.read_csv('cia_factbook.csv', delimiter=';') # Berkna densitet fr alla rader och ta bort nan/inf rader. modified = df_cia_factbook.eval( 'density = population / area' ).query( 'density == density and density != @inf' ) # Visa-lnder meny. assignment_2_menu(modified) Task2-Plot NameError: name 're' is not defined