Q7a: 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 . (Note you'll likely want to look at the output in both to figure out how to best do this. Again using indexing, store the name of the candy that is both fruity and chocolate in the variable candy_name . N # YOUR CODE HERE df.loc[:,['fruity_choco']]

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Using Python

df.loc[:, ['A', 'B', 'C']]
This would return all rows (indicated by the : ) and three columns ['A', 'B', 'c'].
Alternatively, integer-based indexing could be used with iloc (where the i stands for index):
df.iloc[0:5, 0:5]
This would return the first five rows and columns of the dataframe df . (As a reminder: when indicating ranges in Python, the final value is not included in
what is returned. So, this returns the zero-th through the 4th indices. Index 5 is not included in the output)
Python also uses zero-based indexing which means the first element is indexed as zero, the second has index 1, and so on.
Q7a: 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 . (Note you'll likely want to look at the output in both to figure out how to best do this.
Again using indexing, store the name of the candy that is both fruity and chocolate in the variable candy_name .
I # YOUR CODE HERE
df.loc[:,['fruity_choco']]
10]:
fruity_choco
1
1
1
2
3
4
1
...
80
1
81
82
83
84
1
85 rows x 1 columns
I assert type(both)
assert both.shape == (1, 10)
pd. DataFrame
==
NameError
Traceback (most recent call last)
<ipython-input-41-a9deb574df58> in <module>
== pd. DataFrame
---> 1 assert type(both)
2 assert both.shape == (1, 10)
NameError: name 'both' is not defined
Transcribed Image Text:df.loc[:, ['A', 'B', 'C']] This would return all rows (indicated by the : ) and three columns ['A', 'B', 'c']. Alternatively, integer-based indexing could be used with iloc (where the i stands for index): df.iloc[0:5, 0:5] This would return the first five rows and columns of the dataframe df . (As a reminder: when indicating ranges in Python, the final value is not included in what is returned. So, this returns the zero-th through the 4th indices. Index 5 is not included in the output) Python also uses zero-based indexing which means the first element is indexed as zero, the second has index 1, and so on. Q7a: 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 . (Note you'll likely want to look at the output in both to figure out how to best do this. Again using indexing, store the name of the candy that is both fruity and chocolate in the variable candy_name . I # YOUR CODE HERE df.loc[:,['fruity_choco']] 10]: fruity_choco 1 1 1 2 3 4 1 ... 80 1 81 82 83 84 1 85 rows x 1 columns I assert type(both) assert both.shape == (1, 10) pd. DataFrame == NameError Traceback (most recent call last) <ipython-input-41-a9deb574df58> in <module> == pd. DataFrame ---> 1 assert type(both) 2 assert both.shape == (1, 10) NameError: name 'both' is not defined
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY