Question
USING PYTHON Using this data, write a python code for the following questions: 1. Read the file data.csv as a dataFrame named df . Assign
USING PYTHON
Using this data, write a python code for the following questions:
1. Read the file data.csv as a dataFrame named df. Assign the column 'Municipal' as the row index.
Hint:
1. Use read_csv to read the file to be a dataFrame
2. Set the argument index_col to be the name of the first column
3. Set the argument thousands to be ',' since there are thousand separators in the file
2. What is the name of the municipality with the most population in 2017?
3. How many municipalities are there in each county? The output should be a Series with the county name as the index and the number as the value.
Hint: Choose the column of 'County' and use values_counts function to calculate the frequencies of values in that column.
4. What municipality has the largest change in population from 2010 to 2017? The output should be a string.
5. What is the total population of the Essex county in 2017? The output should be an integer.
Hint:
Create a new dataFrame which selects the rows that are 'Essex' in the column 'County'
Choose the column 'POP2017' of the new dataFrame
Apply sum method to get the sum of that column
6. Find the top five municipalities in population of 2017. List their county and the population of 2017. The output should be a dataFrame with two columns 'County' and 'POP2017', and the municipality as the index.
Hint:
Sort df by the values in the column 'POP2017' in descending order.
Choose the first 5 rows of the sorted df, and select their columns 'County' and 'POP2017'
This is a screenshot of the csv file:
Introduction to the data The file name is data.csv. It contains the information of all municipalities in New Jersery. The meaning of each colunmn is as follows Municipality: the name of the municipality County: the county that the municipality belongs to POP2010: the population of a municipality in 2010 POP2017: the population of a municipality in 2017 MunicipalType: the type of a municipality In this assignment, you need to read the csv file as a dataFrame. Then, please use the functions and operations in pandas to answer the following questions. In [5]: # import pandas # Don't delete this cell import pandas as pd Introduction to the data The file name is data.csv. It contains the information of all municipalities in New Jersery. The meaning of each colunmn is as follows Municipality: the name of the municipality County: the county that the municipality belongs to POP2010: the population of a municipality in 2010 POP2017: the population of a municipality in 2017 MunicipalType: the type of a municipality In this assignment, you need to read the csv file as a dataFrame. Then, please use the functions and operations in pandas to answer the following questions. In [5]: # import pandas # Don't delete this cell import pandas as pdStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started