import pandas as pd
pd.read_csv("https://github.com/sakeefkarim/soci-269-f25/raw/refs/heads/main/data/assignments/coding%20assignment%202/anes_2020_truncated.csv")Soci–269
Coding Assignment in Python

Basic Expectations
As noted in your syllabus, you are required to submit a coding assignment by Friday, November 21st at 8:00 PM. For this assignment, you will clean a dataset in Python , report basic descriptive statistics, create simple data visualizations, and provide some substantive interpretations. You must also include your script file (a .ipynb document) as part of your submission. Once you’re done, please submit your materials via Moodle.
Please remember to submit (i) the code you used to complete the assignment along with (ii) a text-based summary of your results and interpretations.
The Data
Description
You will be working with a truncated version of the 2020 American National Elections Studies (ANES) Time Series. The dataset was prepared using the {anesr} package.
You can access the data through one of three channels:
- By copying and pasting the script below directly into
Colab:
By directly downloading the
.csvfile.By cloning our companion GitHub repository.
Variables
Learn more about the variables in your data by using the codebook embedded below.
Coding Tasks
Report the mean for all numeric variables in the data.1
Report the distribution—i.e., percentage share—of Democrats and Republicans across three age groups: under 40 years old, between 40 and 60 years old, and above 60 years old. Provide separate estimates for individuals who identify as Democrats and those who identify as Republicans. Your estimates should include partisan “leaners”: to wit, Independents who lean Democrat should be classified as Democrats, and Independents who lean Republican should be classified as Republicans.
Report the percentage of Democrats and Republicans who have never married. As before, classify Independents who lean Republican as Republicans, and Independents who lean Democrat as Democrats.
When writing up your results for Questions 1-3, please use simple tables and plots to present your results in lieu of detailed narrative exposition.
If you can generate weighted estimates for Questions 1-3, you will receive a small bonus.
- Once again, explore the numeric (read:
float) variables in your data. What are they capturing? Are they meaningfully patterned by the sociodemographic variables included in your truncated dataset? Usingseaborn, generate four visualizations that provide preliminary insights based on your exploratory assessments and hunches. Include figure captions.
Narrative Interpretation
Pick one or two of your plots from Question 4. Then, drawing on relevant social scientific research,2 carefully interpret the results. Clearly articulate how your findings relate to (i.e., refine or complicate) extant understandings of \(x\), your social phenomenon of interest. Do your results offer novel or interesting insights? Are there any unexpected patterns that emerge, and if so, how can you account for them? Thoughtfully connect your interpretation to existing work, highlighting areas of convergence or disjuncture before clarifying what your graphic reveals about the social mechanisms animating \(x\). Remember, you have to be brief: papers must be between 5 and 10 pages.
Formatting Guidelines
You are free to prepare your second assignment in Microsoft Word, Google Docs, \(\LaTeX\), RMarkdown or Quarto. Concretely, this means you can submit your assignment as a .docx file or as a . Your main text must be double-spaced and formatted in a 12-point font. Margins should be set to 1 inch on all sides (top, bottom, left, and right). You are free to use either an APA or ASA citation style to manage the references you include.
If you haven’t done so already, you may want to invest in Zotero to manage your citations.
You must use subheadings to organize your arguments.