Question
Q6a: Slicing in PYTHON The concept of slicing can be combined with conditionals. For example, you can return all rows of a particular value. Using
Q6a: Slicing in PYTHON
The concept of slicing can be combined with conditionals. For example, you can return all rows of a particular value.
Using value_counts() above on the fruity_choco column we created, we see that there is one candy that is both chocolate and fruity in our dataset. Let's figure out which candy that was!
Use slicing to return the row from df where fruity_choco indicated the candy was both fruity and chocolate.
Store this DataFrame (which will have a single row) as both. Again using indexing, store the name of the candy that is both fruity and chocolate in the variable candy_name.
Q6a: Slicing The concept of slicing can be combined with conditionals. For example, you can return all rows of a particular value. Using value_counts above on the fruity_choco column we created, we see that there is one candy that is both chocolate and fruity in our dataset. Let's figure out which candy that was! Use slicing to return the row from df where fruity_choco indicated the candy was both fruity and chocolate. Store this DataFrame (which will have a single row) as both. Again using indexing, store the name of the candy that is both fruity and chocolate in the variable candy_name. In [76]: # YOUR CODE HERE df.loc[:,['fruity_choco']] Out[76] : fruity_choco 85 rows x 1 columns In [77]: assert type (both) == pd.DataFrame assert both.shape == (1, 10) assert isinstance (candy_name, str) Q6a: Slicing The concept of slicing can be combined with conditionals. For example, you can return all rows of a particular value. Using value_counts above on the fruity_choco column we created, we see that there is one candy that is both chocolate and fruity in our dataset. Let's figure out which candy that was! Use slicing to return the row from df where fruity_choco indicated the candy was both fruity and chocolate. Store this DataFrame (which will have a single row) as both. Again using indexing, store the name of the candy that is both fruity and chocolate in the variable candy_name. In [76]: # YOUR CODE HERE df.loc[:,['fruity_choco']] Out[76] : fruity_choco 85 rows x 1 columns In [77]: assert type (both) == pd.DataFrame assert both.shape == (1, 10) assert isinstance (candy_name, str)
Step 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