For this assignment, use the president_heights.csv file found in the Brightspace module. You *WILL NOT NEED TO SUBMIT THE president_heights.csv FILE TO CODEGRADE* You should use Pandas (import pandas...



  • For this assignment, use the president_heights.csv file found in the Brightspace module. You *WILL NOT NEED TO SUBMIT THE president_heights.csv FILE TO CODEGRADE*

  • You should use Pandas (import pandas as pd) for this assignment.

  • Create a program, presidents.py, that takes two arguments. These arguments will correspond to the start and stop of a slice, respectively.  It will slice the heights column in the president_heights.csv files.

  • Then print off the average height, rounded to two decimals, of the selected presidents in the following form:



The average height of presidents number x to y is z



          Where:



  • x = start of the slice

  • y = end of the slice

  • z = calculated average



Note: There would be 6 presidents if the “The average height of presidents number 4 to 10 is ...”


This question has been solved but it produces the error below, can the code be corrected?



  1. Traceback (most recent call last):

  2. File"presidents.py",line12,in

  3. height=data_df[x:y]['height(cm)']

  4. File"/usr/local/lib/python3.7/dist-packages/pandas/core/frame.py",line3430,in__getitem__

  5. indexer=convert_to_index_sliceable(self,key)

  6. File"/usr/local/lib/python3.7/dist-packages/pandas/core/indexing.py",line2329,inconvert_to_index_sliceable

  7. returnidx._convert_slice_indexer(key,kind="getitem")

  8. File"/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/numeric.py",line244,in_convert_slice_indexer

  9. returnsuper()._convert_slice_indexer(key,kind=kind)

  10. File"/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py",line3719,in_convert_slice_indexer

  11. self._validate_indexer("slice",key.start,"getitem")

  12. File"/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py",line5719,in_validate_indexer

  13. raiseself._invalid_indexer(form,key)

  14. TypeError: cannot do slice indexing on RangeIndex with these indexers [4] of type str

Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here