Home assignment 2#
Last updated: 2024-05-12 09:35:27
Question 1#
Read the DEM of the Carmel in
'carmel.csv'
into anndarray
object.Calculate how many cells/pixels are in each of 100-m elevation “bins” starting with
-100
and ending with600
meters, i.e.,-100
-0
,0
-100
, …,500
-600
.The counts need to include the start point but not the end point, i.e., the first bin is \(-100 ≤ x < 0\), the second bin is \(0 ≤ x < 100\), and so on.
Store the results in a dictionary, with the dictionary keys being the bin labels, and dictionary values being the pixel counts.
Print the dictionary.
{'-100 - 0': 380,
'0 - 100': 80438,
'100 - 200': 40877,
'200 - 300': 20841,
'300 - 400': 8998,
'400 - 500': 5116,
'500 - 600': 476}
Question 2#
Read the
'world_cities.csv'
file into aDataFrame
object.Calculate a new column named
'pop_M'
(population in millions), by transforming the'pop'
(population) column.Remove the original
'pop'
column.Choose a city that starts with the same English letter as your first name (for example,
'Mexico City'
if your first name is Michael).Subset the six biggest (i.e., largest population sizes) cities from the country where your selected city is. (Do not use the country name string in the code; use an expression which returns it.)
Print the result.
city | country | lat | lon | capital | pop_M | |
---|---|---|---|---|---|---|
23660 | Mexico City | Mexico | 19.43 | -99.14 | 1 | 8.659409 |
10135 | Ecatepec | Mexico | 19.60 | -99.05 | 0 | 1.844447 |
13180 | Guadalajara | Mexico | 20.67 | -103.35 | 0 | 1.637213 |
16484 | Juarez | Mexico | 31.74 | -106.49 | 0 | 1.449006 |
38138 | Tijuana | Mexico | 32.53 | -117.02 | 0 | 1.427118 |
30002 | Puebla | Mexico | 19.05 | -98.22 | 0 | 1.416551 |