\[ \begin{align}\begin{aligned}\newcommand\blank{~\underline{\hspace{1.2cm}}~}\\% Bold symbols (vectors) \newcommand\bs[1]{\mathbf{#1}}\\% Differential \newcommand\dd[2][]{\mathrm{d}^{#1}{#2}} % use as \dd, \dd{x}, or \dd[2]{x}\\% Poor man's siunitx \newcommand\unit[1]{\mathrm{#1}} \newcommand\num[1]{#1} \newcommand\qty[2]{#1~\unit{#2}}\\\newcommand\per{/} \newcommand\squared{{}^2} \newcommand\cubed{{}^3} % % Scale \newcommand\milli{\unit{m}} \newcommand\centi{\unit{c}} \newcommand\kilo{\unit{k}} \newcommand\mega{\unit{M}} % % Percent \newcommand\percent{\unit{{\kern-4mu}\%}} % % Angle \newcommand\radian{\unit{rad}} \newcommand\degree{\unit{{\kern-4mu}^\circ}} % % Time \newcommand\second{\unit{s}} \newcommand\s{\second} \newcommand\minute{\unit{min}} \newcommand\hour{\unit{h}} % % Distance \newcommand\meter{\unit{m}} \newcommand\m{\meter} \newcommand\inch{\unit{in}} \newcommand\foot{\unit{ft}} % % Force \newcommand\newton{\unit{N}} \newcommand\kip{\unit{kip}} % kilopound in "freedom" units - edit made by Sri % % Mass \newcommand\gram{\unit{g}} \newcommand\g{\gram} \newcommand\kilogram{\unit{kg}} \newcommand\kg{\kilogram} \newcommand\grain{\unit{grain}} \newcommand\ounce{\unit{oz}} % % Temperature \newcommand\kelvin{\unit{K}} \newcommand\K{\kelvin} \newcommand\celsius{\unit{{}^\circ C}} \newcommand\C{\celsius} \newcommand\fahrenheit{\unit{{}^\circ F}} \newcommand\F{\fahrenheit} % % Area \newcommand\sqft{\unit{sq\,\foot}} % square foot % % Volume \newcommand\liter{\unit{L}} \newcommand\gallon{\unit{gal}} % % Frequency \newcommand\hertz{\unit{Hz}} \newcommand\rpm{\unit{rpm}} % % Voltage \newcommand\volt{\unit{V}} \newcommand\V{\volt} \newcommand\millivolt{\milli\volt} \newcommand\mV{\milli\volt} \newcommand\kilovolt{\kilo\volt} \newcommand\kV{\kilo\volt} % % Current \newcommand\ampere{\unit{A}} \newcommand\A{\ampere} \newcommand\milliampereA{\milli\ampere} \newcommand\mA{\milli\ampere} \newcommand\kiloampereA{\kilo\ampere} \newcommand\kA{\kilo\ampere} % % Resistance \newcommand\ohm{\Omega} \newcommand\milliohm{\milli\ohm} \newcommand\kiloohm{\kilo\ohm} % correct SI spelling \newcommand\kilohm{\kilo\ohm} % "American" spelling used in siunitx \newcommand\megaohm{\mega\ohm} % correct SI spelling \newcommand\megohm{\mega\ohm} % "American" spelling used in siunitx % % Capacitance \newcommand\farad{\unit{F}} \newcommand\F{\farad} \newcommand\microfarad{\micro\farad} \newcommand\muF{\micro\farad} % % Inductance \newcommand\henry{\unit{H}} \newcommand\H{\henry} \newcommand\millihenry{\milli\henry} \newcommand\mH{\milli\henry} % % Power \newcommand\watt{\unit{W}} \newcommand\W{\watt} \newcommand\milliwatt{\milli\watt} \newcommand\mW{\milli\watt} \newcommand\kilowatt{\kilo\watt} \newcommand\kW{\kilo\watt} % % Energy \newcommand\joule{\unit{J}} \newcommand\J{\joule} % % Composite units % % Torque \newcommand\ozin{\unit{\ounce}\,\unit{in}} \newcommand\newtonmeter{\unit{\newton\,\meter}} % % Pressure \newcommand\psf{\unit{psf}} % pounds per square foot \newcommand\pcf{\unit{pcf}} % pounds per cubic foot \newcommand\pascal{\unit{Pa}} \newcommand\Pa{\pascal} \newcommand\ksi{\unit{ksi}} % kilopound per square inch % NOTE: do NOT define \bar -- it is the built-in LaTeX accent used by \bar{x}, % \bar{y} (sample means). Redefining it made those render as the word "bar". \newcommand\barunit{\unit{bar}} \end{aligned}\end{align} \]

Nov 16, 2026 | 919 words | 9 min read

11.3.1. PY: Data Analysis and Visualization#

Task #1: NYC Elevator Maps#

Background#

Elevators require regular inspection to ensure functionality and passenger safety. Municipal agencies maintain lists of elevators in their jurisdiction. You have been provided a dataset (“data_NYC_elevators.csv”) of the location and type of elevators currently in use in New York City (which is composed of five boroughs: Manhattan, Queens, the Bronx, Brooklyn, and Staten Island). Use your knowledge of pandas dataframes, plotting, plot formatting, and logic operations to create three figures that display the latitude and longitude of elevators located in New York. Complete this task using the provided data.

List of Registered elevator devices in New York City, Sept 2015

Column

Description

DV_DEVICE_NUMBER

NYC Department of Buildings device identification number

Device Type

Type of elevator

Borough

Section of NYC: Bronx, Brooklyn, Manhattan, Queens, or Staten Island

ZIP_CODE

US postal zip code of elevator location

LATITUDE

Elevator latitude (decimal degrees)

LONGITUDE

Elevator longitude (decimal degrees)

Required Files#

  1. Download the Python template ENGR131_Python_Template.py and save it as 11_3_1_username.py.

  2. Download the data file data_NYC_elevators.csv and save locally (same file name) for importing and analyzing the data. Do not submit this file to Gradescope

  3. Create and save your figures as PNG files:

    • Figure 1: 11_3_1_nyc_elevator_map_username.png

    • Figure 2: 11_3_1_nyc_elevator_map_revised_username.png

    • Figure 3: 11_3_1_manhattan_elevator_map_username.png

  4. Create and save your filtered Manhattan elevator data as a CSV file: 11_3_1_manhattan_elevator_data_username.csv

Reminder

Review and reference the Python Style Guide to create a professionally formatted code file. For example, remember to provide detailed comments throughout your code so anyone can read them and understand what your program does!


Program Requirements#

Part 1: Load, View and Prep Data for Plotting#

  1. Import the required libraries:

    • pandas

    • matplotlib.pyplot

  2. Load “data_NYC_elevators.csv” into a pandas DataFrame called elev_df.

  3. Display:

    • The first 10 rows of elev_df

    • Column names

    • Number of rows and columns

  4. Rename the latitude and longitude columns in elev_df to “Latitude” and “Longitude”.

Part 2: Plot Figure 1#

  1. Create a scatter plot of latitude vs. longitude of each elevator. The data markers should be blue dots of size 10. Figure size should be 8 x 6.

    Use plt.axis('equal') to set the aspect ratio so that tick mark increments on the x-and y-axis are equal in size to mimic a 2D grid.

  2. Export Figure 1 as a PNG using the Figure 1 file name specified in the Required Files section.

Part 3: Clean Data and Plot Figure 2#

After plotting Figure 1, you should see a bad data point.

  1. Write code to remove the bad data point from the data without hardcoding any values. The process of identifying and correcting or removing invalid data points, outliers, and missing values within a dataset is referred to as “cleaning the data”.

  2. Plot the revised latitude and longitude data.

    • The plot title in Figure 2 must be differentiated from Figure 1 in a meaningful way.

    • Use green dot data markers (size 1) and increase the figure size to 10 x 8. This will allow you to see some road and park detail on the map.

  3. Export Figure 2 as a PNG using the Figure 2 file name specified in the Required Files section.

Part 4: Filter Manhattan Data and Plot Figure 3#

The zip codes for Manhattan are 10001-10075, -10128, and -10280.

  1. Filter elev_df by the latitude and longitude of only the Manhattan elevators without hardcoding any array or linear indices. Store this filtered data into a new DataFrame called man_elev_df.

  2. Display the first 5 rows of man_elev_df to ensure the DataFrame only includes data for Manhattan elevators.

  3. Plot latitude vs. longitude of the Manhattan subset of elevators in Figure 3. Use purple dot data markers of size 1. You can see road and park detail in the map if you increase the figure size to 10 x 8.

    Note: The large rectangular area with almost no elevators is Central Park.

  4. Export Figure 3 as a PNG using the Figure 3 file name specified in the Required Files section.

  5. Display the number of elevators in Manhattan.

Part 5: Write Data to New File#

Write the Manhattan elevator data in man_elev_df to a new CSV using the filename specified in the Required Files section.


Sample Output#

Sample Output

$ python3 11_3_1_username.pyNYC Elevator Data (First 10 rows): DV_DEVICE_NUMBER Device Type Borough ZIP_CODE LATITUDE (decimal degrees) LONGITUDE (decimal degrees)0 5D1 Dumbwaiter (D) Staten Island 10301 40.589722 -74.1006591 5D116 Dumbwaiter (D) Staten Island 10304 40.600237 -74.0867862 5D296 Dumbwaiter (D) Staten Island 10302 40.637563 -74.1311303 5D5001 Dumbwaiter (D) Staten Island 10301 40.635731 -74.0891594 5D5002 Dumbwaiter (D) Staten Island 10304 40.595568 -74.0906145 5D5016 Dumbwaiter (D) Staten Island 10304 40.592447 -74.1096326 5D5017 Dumbwaiter (D) Staten Island 10305 40.584516 -74.0854987 5D5019 Dumbwaiter (D) Staten Island 10301 40.613374 -74.1007708 5D5020 Dumbwaiter (D) Staten Island 10304 40.588340 -74.1046579 5D5022 Dumbwaiter (D) Staten Island 10304 40.583531 -74.110482Column names: Index(['DV_DEVICE_NUMBER', 'Device Type', 'Borough', 'ZIP_CODE', 'LATITUDE (decimal degrees)', 'LONGITUDE (decimal degrees)'], dtype='str')Shape (rows, columns): (76061, 6)First 5 rows (Manhattan): DV_DEVICE_NUMBER Device Type Borough ZIP_CODE Latitude Longitude120 1D1 Dumbwaiter (D) Manhattan 10001 40.764453 -73.954143121 1D10000 Dumbwaiter (D) Manhattan 10012 40.727255 -73.999841122 1D10001 Dumbwaiter (D) Manhattan 10003 40.736806 -73.991094123 1D10006 Dumbwaiter (D) Manhattan 10002 40.717711 -73.993034124 1D10007 Dumbwaiter (D) Manhattan 10002 40.717711 -73.993034The number of elevators in Mahattan is 43596.

Aside from your figures, ensure that your program output matches the sample output exactly to ensure you receive full points from the auto grader.


Gradescope Submission#

Attention

Before submitting your python file, comment all lines with plt.show() for autograding purposes.

  1. Save Deliverables: Ensure all required assignment files are saved and named exactly as specified in the assignment instructions. If a template file name contains the word template, replace only that word with your Purdue username. When a task lists more than one deliverable, such as a workbook and a report, submit each deliverable to its own matching Gradescope assignment instead of combining them into one upload.

  2. Navigate to Gradescope: Log in to Gradescope. From your Dashboard, open the assignment.

  3. Upload your work: Select the Upload submission method. Drag and drop all required files (or a compressed .zip folder) into Gradescope, and select Upload.

  4. Confirm Submission: When your upload is successful, you will see a confirmation message on your screen and receive an automated email receipt.

  5. Add Team Members (if applicable): If this is a team assignment, add all team members to the submission. Each teammate should confirm they can see the submission in their own Gradescope account. For help, visit Gradescope’s documentation on adding team members.

  6. Review Autograder Results: Wait a few minutes for the autograder to evaluate the relevant files. Scroll down to view any failed test cases. If you need assistance interpreting the output or errors, ask your teaching team.

  7. Resubmit if Necessary: You can edit your files and select Resubmit as many times as you need before the assignment deadline. Only your final, active submission is graded. (Note: If you need to resubmit, you must upload all required files for the assignment again).

For a detailed walkthrough, review the official Gradescope Submission Guide.