tankaraco
tankaraco
My Data Analyst Journey
2 posts
Don't wanna be here? Send us removal request.
tankaraco ยท 2 months ago
Text
My first program
```python
import pandas as pd
Load data
mydata = pd.read_csv('ool_pds.csv', low_memory=False)
print(f'๐Ÿ“Š Number of observations: {len(mydata)}') print(f'๐Ÿงฉ Number of variables: {len(mydata.columns)}')
--------------------------------------
๐ŸŸฉ Race/Ethnicity (PPETHM)
race_labels = { 1: 'White, Non-Hispanic', 2: 'Black, Non-Hispanic', 3: 'Other, Non-Hispanic', 4: 'Hispanic', 5: '2+ Races, Non-Hispanic' }
race_counts = mydata['PPETHM'].value_counts(sort=False) race_percentages = mydata['PPETHM'].value_counts(sort=False, normalize=True)
race_counts.index = race_counts.index.map(race_labels) race_percentages.index = race_percentages.index.map(race_labels)
print('\n๐ŸŸฉ Race/Ethnicity - Counts:') print(race_counts)
print('\n๐ŸŸฉ Race/Ethnicity - Percentages:') print(race_percentages)
--------------------------------------
๐ŸŸฅ Political Identification (W1_C1)
political_labels = { 1: 'Republicans', 2: 'Democrats', 3: 'Independents', 4: 'Something else', 5: 'Refused' }
party_counts = mydata['W1_C1'].value_counts(sort=False) party_percentages = mydata['W1_C1'].value_counts(sort=False, normalize=True)
party_counts.index = party_counts.index.map(political_labels) party_percentages.index = party_percentages.index.map(political_labels)
print('\n๐ŸŸฅ Party Identification - Counts:') print(party_counts)
print('\n๐ŸŸฅ Party Identification - Percentages:') print(party_percentages)
--------------------------------------
๐ŸŸช Age Category (PPAGECAT)
age_labels = { 1: '18โ€“24', 2: '25โ€“34', 3: '35โ€“44', 4: '45โ€“54', 5: '55โ€“64', 6: '65โ€“74', 7: '75+' }
age_filtered = mydata[mydata['PPAGECAT'] != 99] # Exclude under 18 age_counts = age_filtered['PPAGECAT'].value_counts(sort=False) age_percentages = age_filtered['PPAGECAT'].value_counts(sort=False, normalize=True)
age_counts.index = age_counts.index.map(age_labels) age_percentages.index = age_percentages.index.map(age_labels)
print('\n๐ŸŸช Age Group (18+) - Counts:') print(age_counts)
print('\n๐ŸŸช Age Group (18+) - Percentages:') print(age_percentages) ```
Output:
๐Ÿ“Š Number of observations: 2294 ๐Ÿงฉ Number of variables: 436
๐ŸŸฉ Race/Ethnicity - Counts: PPETHM Hispanic 123 Black, Non-Hispanic 1278 White, Non-Hispanic 814 Other, Non-Hispanic 46 2+ Races, Non-Hispanic 33 Name: count, dtype: int64
๐ŸŸฉ Race/Ethnicity - Percentages: PPETHM Hispanic 0.053618 Black, Non-Hispanic 0.557105 White, Non-Hispanic 0.354839 Other, Non-Hispanic 0.020052 2+ Races, Non-Hispanic 0.014385 Name: proportion, dtype: float64
๐ŸŸฅ Party Identification - Counts: W1_C1 Republicans 331 Democrats 1251 Independents 555 Something else 108 NaN 49 Name: count, dtype: int64
๐ŸŸฅ Party Identification - Percentages: W1_C1 Republicans 0.144289 Democrats 0.545336 Independents 0.241935 Something else 0.047079 NaN 0.021360 Name: proportion, dtype: float64
๐ŸŸช Age Group (18+) - Counts: PPAGECAT 55โ€“64 514 35โ€“44 360 65โ€“74 329 18โ€“24 237 45โ€“54 457 25โ€“34 289 75+ 108 Name: count, dtype: int64
๐ŸŸช Age Group (18+) - Percentages: PPAGECAT 55โ€“64 0.224063 35โ€“44 0.156931 65โ€“74 0.143418 18โ€“24 0.103313 45โ€“54 0.199215 25โ€“34 0.125981 75+ 0.047079 Name: proportion, dtype: float64
Description:
The sample includes 2,294 observations and 436 variables. Among the participants, Black, Non-Hispanic individuals make up the largest group (56%), followed by White, Non-Hispanic (35%). Only a small portion identified as Hispanic (5%) or multiracial (1.4%).
In terms of political identity, a majority identified as Democrats (54.5%), while Republicans and Independents represented 14% and 24%, respectively. About 2% of the data is missing for this question.
Regarding age, most respondents are between 35 and 74 years old, with the largest single group being ages 55โ€“64. Very few are over 75, and those under 18 were excluded from the analysis.
0 notes
tankaraco ยท 3 months ago
Text
Race & Political ID
Is party identification associated with race in the US? I will use the Outlook for Life Survey data set to answer this question.
In the United States, party identification is significantly associated with race, with minority racial groups (African American, Hispanic, and Asian American) more likely to identify as Democrats, while white Americans, particularly those without a college degree, are more likely to identify as Republicans.
Variables Considered
Race/Ethnicity: African American, Hispanic/Latino, Asian American, and White (Abramowitz & Webster, 2018).
Education Level: College-educated vs. non-college-educated voters (Pew Research Center, 2024).
Socioeconomic Status: Income levels and economic mobility influence political affiliation (Tesler, 2016).
Geographic Location: Urban voters lean Democratic, while rural voters lean Republican (Hopkins, 2018).
Religious Affiliation: Evangelical Christians strongly support Republicans, while non-religious groups lean Democratic (Putnam & Campbell, 2012).
Immigration Status: First-generation immigrants show variation in party alignment based on country of origin and policy concerns (Wong et al., 2011).
Patterns of Findings
African Americans: Over 80% identify as Democratic, largely due to civil rights policies and historical realignment (Dawson, 1994).
Hispanic/Latino Voters: Lean Democratic (~60%), with variations among subgroups (e.g., Cuban Americans lean Republican) (Abrajano & Alvarez, 2010).
Asian Americans: Increasing Democratic alignment (~65%), with significant differences by national origin (Ramakrishnan et al., 2017).
White Voters: White non-college voters lean Republican, while white college-educated voters are shifting Democratic (Pew Research Center, 2020).
Education Divide: College-educated voters trend Democratic, while non-college-educated voters trend Republican (Sides et al., 2018).
Religious Influence: Evangelicals remain a key Republican base, while Jewish and Muslim voters lean Democratic (Putnam & Campbell, 2012).
1 note ยท View note