Created
April 6, 2017 22:06
-
-
Save onurvarol/ba101ebed3c9cd966d0e58f15932e999 to your computer and use it in GitHub Desktop.
Parse feature names in Fragile Families Challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse_codebook_data(fname): | |
fNames = dict() | |
with open(fname, 'r') as fl: | |
lstate = False | |
for line in fl: | |
if line.startswith('-----'): | |
lstate = True | |
else: | |
if lstate: | |
while ' ' in line: | |
line = line.replace(' ', ' ') | |
#print line | |
temp = line.strip().split(' ') | |
fNames[temp[0]] = ' '.join(temp[1:]) | |
lstate = False | |
return fNames | |
featureNames = dict() | |
# Looking for a path that has all feature description files | |
for fname in glob.glob('data/codebooks/ff*.txt'): | |
featureNames.update(parse_codebook_data(fname)) | |
for f in featureNames: | |
if 'education' in featureNames[f]: | |
print '[{}]: {}'.format(f, featureNames[f]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment