• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 4 out of 77 pages
Exam (elaborations)

COGS 108 Assignment 2: pandas & Data Visualization | 2026 Updated with complete solutions GRADE A+

Document preview thumbnail
Preview 4 out of 77 pages

COGS 108 Assignment 2: pandas & Data Visualization | 2026 Updated with complete solutions GRADE A+

Content preview

COGS 108 ASSIGNMENT 2: PANDAS &
DATA VISUALIZATION | 2026 UPDATED
WITH COMPLETE SOLUTIONS.
149 Questions with Answers and Detailed Rationales


100 PERCENT GUARANTEED PASS


INSTANT DOWNLOAD ANSWERS INCLUDED



IMPORTANCE OF THIS DOCUMENT
This comprehensive examination preparation guide has been meticulously developed to help you succeed in the
COGS 108 ASSIGNMENT 2: PANDAS & DATA VISUALIZATION | 2026 UPDATED WITH COMPLETE
SOLUTIONS.. It contains 149 carefully selected questions that reflect the most current exam content and testing
strategies. Each question is accompanied by a correct answer and a detailed rationale that explains the
underlying pathophysiology, pharmacology, or clinical reasoning.

Self-Assessment – Test your knowledge and Exam Preparation – Familiarize yourself with the
identify areas requiring further question format and content
study areas

Concept Reinforcement – Deepen your Confidence Building – Develop test-taking
understanding through strategies and reduce
evidence-based exam anxiety
rationales
Time Management – Practice answering
questions under simulated
exam conditions




Review Summary 149 Questions


Foundations - Application - COGS 108 Assignment 2 Pandas & DATA Visualization 2026 Updated WITH
Complete Solutions Cognitive Science / DATA Science Pandas & DATA Visualization Undergraduate YEAR
2-3 Lower-division DATA Science CORE
All answers with rationales

,Table of Contents

Content Area Questions Key Topics

Introduction TO Pandas 1-25 Dataframe, Columns, Values, Pandas, Operation
Series AND Dataframe
Objects

DATA Loading AND 26-50 Dataframe, Column, Right, Expression, Index
Inspection READ CSV HEAD
INFO Describe

Indexing Selection AND 51-75 Dataframe, Column, Score, Expression, Values
Filtering LOC ILOC Boolean
Masks

DATA Cleaning Handling 76-100 Dataframe, Column, Right, Values, Visualization
Missing Values Duplicates
AND TYPE Conversion

Grouping AND Aggregation 101-125 Column, Dataframe, Values, Returns, CITY
Groupby AGG Transform

Merging Joining AND 126-149 Dataframe, Chart, Expression, Column, Choice
Concatenating Dataframes

TOTAL 149 All questions include answers and detailed rationales

,Section A - Introduction TO Pandas Series AND Dataframe
Objects

Q1.
Given df with a non-default integer index (e.g., 10, 20, 30), what does df.loc[10:20] return
compared to df.iloc[10:20]?


A. Both return the same rows because the B. loc returns rows with labels 10 through 20
labels equal their positions here. inclusive; iloc returns rows at positions 10
through 19.

C. loc returns rows at positions 10 through D. Both raise KeyError because the integer
20; iloc returns rows with labels 10 through index is not a RangeIndex.
19.
Correct: B - loc returns rows with labels 10 through 20 inclusive; iloc returns rows at
positions 10 through 19.


Rationale:loc slices by label and is inclusive on both endpoints, so labels 10 and 20 are both
included. iloc slices by zero-based position and is exclusive on the stop, returning positions
10 through 19. This distinction is a core pandas indexing concept tested in Assignment 2.
Why the other answers are wrong:
A. Labels and positions coincide only when the index is a default RangeIndex; here they
diverge.
C. loc uses labels (inclusive), not positions, and iloc uses positions (exclusive stop), not labels.
D. A non-default integer index is perfectly valid and does not raise KeyError.
Reference: pandas Documentation (2025). Indexing and selecting data: .loc vs .iloc.


Q2.
A DataFrame df has columns ['A','B','C']. After running df2 = df[['A','B']].copy() and then
df2['A'] = 0, what is the state of df?


A. Column 'A' in df is also set to 0 because B. df raises a SettingWithCopyWarning and
of view semantics. 'A' becomes 0.

C. df is unchanged because .copy() creates D. df loses columns 'B' and 'C' because of
an independent DataFrame. chained selection.
Correct: C - df is unchanged because .copy() creates an independent DataFrame.


Rationale:.copy() returns a deep copy, so modifications to df2 do not propagate to df. Without
.copy(), the chained selection could produce a view and trigger SettingWithCopyWarning.
This tests understanding of view vs copy semantics in pandas.
Why the other answers are wrong:




Page 3

, Section A - Introduction TO Pandas Series AND Dataframe Objects

A. Only views propagate changes; .copy() explicitly breaks the link to the parent.

B. No warning is raised because .copy() removes ambiguity about view/copy behavior.

D. Selecting a subset of columns never mutates the original DataFrame's schema.

Reference: McKinney, W. (2022). Python for Data Analysis, 3rd Ed., Ch. 5.


Q3.
Which pandas operation best converts a wide DataFrame with columns
['id','2023','2024','2025'] into a long/tidy format with columns ['id','year','value']?


A. df.pivot(index='id', columns='year', B. pd.melt(df, id_vars='id', var_name='year',
values='value') value_name='value')

C. df.groupby('id').agg(list) D. df.stack(level=0).unstack()
Correct: B - pd.melt(df, id_vars='id', var_name='year', value_name='value')


Rationale:pd.melt reshapes wide to long by unpivoting specified columns into variable/value
pairs, exactly producing id-year-value triples. pivot does the reverse (long to wide). This is a
canonical tidy-data transformation in Assignment 2.
Why the other answers are wrong:
A. pivot converts long to wide, the opposite of what is needed here.
C. groupby().agg(list) aggregates values into lists but does not create a tidy long format.
D. stack/unstack shuffles MultiIndex levels without producing the requested id-year-value
schema.
Reference: Wickham, H. (2014). Tidy Data. JSS 59(10); pandas reshaping docs.


Q4.
When merging two DataFrames on a key with duplicate values in both, what does the
default how='inner' merge produce?


A. Only rows with unique matches, dropping B. A cartesian product of matching keys (all
duplicates. pairwise combinations).

C. A left join that keeps all left rows. D. An error because duplicate keys are not
allowed in merges.
Correct: B - A cartesian product of matching keys (all pairwise combinations).


Rationale:pandas merges perform a relational join; when keys are duplicated on both sides,
each matching pair produces a row, yielding a cartesian product for those keys. This behavior
is essential for diagnosing inflated row counts after merges.
Why the other answers are wrong:
A. Duplicates are not dropped; they multiply matches.
C. how='inner' keeps only intersecting keys, not all left rows.
D. pandas permits duplicate keys and does not raise an error.




Page 4

Document information

Uploaded on
September 24, 2026
Number of pages
77
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$24.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
ProfReginaBank
4.7
(3)
Sold
20
Followers
2
Items
1486
Last sold
5 days ago




Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions