Q8a: sort_values Specifically, df is currently sorted in alphabetical order by competitor name (candy). What if we were most curious about the sugar percentile of where the candy falls within the...


Use python to solve the following


Q8a: sort_values<br>Specifically, df is currently sorted in alphabetical order by competitor name (candy). What if we<br>were most curious about the sugar percentile of where the candy falls within the dataset?<br>Arrange the rows in df such that the candy with the highest sugarpercent is displayed first<br>and the lowest sugarpercent last. Store this in df.<br>Also, note that when using sort_values , the original indices are retained. So, also reset the<br>index of df so that the highest sugarpercent candy is index 0.<br>I # YOUR CODE HERE<br>df<br>df.sort_values (by=['sugarpercent'], inplace<br>True)<br>%3D<br>I assert df.loc[0,'competitorname'] != '100 Grand'<br>assert np.allclose(df.loc[0,'sugarpercent'], 0.988)<br>AttributeError<br>Traceback (most recent call last)<br><ipython-input-41-81415551f891> in <module><br>-> 1 assert df.loc[0,'competitorname'] != '100 Grand'<br>2 assert np.allclose(df.loc[0,'sugarpercent'], 0.988)<br>---<br>AttributeError: 'NoneType' object has no attribute 'loc'<br>

Extracted text: Q8a: sort_values Specifically, df is currently sorted in alphabetical order by competitor name (candy). What if we were most curious about the sugar percentile of where the candy falls within the dataset? Arrange the rows in df such that the candy with the highest sugarpercent is displayed first and the lowest sugarpercent last. Store this in df. Also, note that when using sort_values , the original indices are retained. So, also reset the index of df so that the highest sugarpercent candy is index 0. I # YOUR CODE HERE df df.sort_values (by=['sugarpercent'], inplace True) %3D I assert df.loc[0,'competitorname'] != '100 Grand' assert np.allclose(df.loc[0,'sugarpercent'], 0.988) AttributeError Traceback (most recent call last) in -> 1 assert df.loc[0,'competitorname'] != '100 Grand' 2 assert np.allclose(df.loc[0,'sugarpercent'], 0.988) --- AttributeError: 'NoneType' object has no attribute 'loc'

Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here