Skip to content

Instantly share code, notes, and snippets.

@justinb4003
Created July 11, 2024 17:11
Show Gist options
  • Save justinb4003/b1cfdcf15f01e2e4bf53fb1b3c89d3d5 to your computer and use it in GitHub Desktop.
Save justinb4003/b1cfdcf15f01e2e4bf53fb1b3c89d3d5 to your computer and use it in GitHub Desktop.
Reading NC Voter data from TXT with minimal memory
import pandas as pd
txtfile = 'ncvoter_Statewide.txt'
coltypes = {
'county_id': 'int',
'voter_reg_num': 'int',
'birth_year': 'int',
'age_at_year_end': 'int',
'county_desc': 'category',
'voter_status_desc': 'category',
'voter_status_reason_desc': 'category',
'res_city_desc': 'category',
'precinct_abbrv': 'category',
'precinct_desc': 'category',
'municipality_abbrv': 'category',
'municipality_desc': 'category',
'ward_abbrv': 'category',
'ward_desc': 'category',
'cong_dist_abbrv': 'category',
'super_court_abbrv': 'category',
'judic_dist_abbrv': 'category',
'nc_senate_abbrv': 'category',
'nc_house_abbrv': 'category',
'county_commiss_abbrv': 'category',
'county_commiss_desc': 'category',
'township_abbrv': 'category',
'township_desc': 'category',
'school_dist_abbrv': 'category',
'school_dist_desc': 'category',
'fire_dist_abbrv': 'category',
'fire_dist_desc': 'category',
'water_dist_abbrv': 'category',
'water_dist_desc': 'category',
'sewer_dist_abbrv': 'category',
'sewer_dist_desc': 'category',
'sanit_dist_abbrv': 'category',
'sanit_dist_desc': 'category',
'rescue_dist_abbrv': 'category',
'rescue_dist_desc': 'category',
'munic_dist_abbrv': 'category',
'munic_dist_desc': 'category',
'dist_1_abbrv': 'category',
'dist_1_desc': 'category',
'vtd_abbrv': 'category',
'vtd_desc': 'category',
}
df = pd.read_csv(txtfile, sep='\t', encoding='ISO-8859-1', dtype=coltypes)
df.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment