Skip to content

Instantly share code, notes, and snippets.

@cpard cpard/
Created May 28, 2016

What would you like to do?
The implementation of the findGender function
def findGender(str):
f = fNames['name'].apply(lambda x: (x, SequenceMatcher(None,str.lower(),x).ratio()))
m = mNames['name'].apply(lambda x: (x, SequenceMatcher(None,str.lower(),x).ratio()))
f = padas.DataFrame([i for i in f], columns=['name','match']).sort_values('match', ascending=False)
m = padas.DataFrame([i for i in m], columns=['name','match']).sort_values('match', ascending=False)
maxMScore = m.iloc[0]['match']
maleName = m.iloc[0]['name']
maxFScore = f.iloc[0]['match']
femaleName = f.iloc[0]['name']
gender = np.nan
if maxFScore > maxMScore:
gender = 'female'
elif maxFScore < maxMScore:
gender = 'male'
femScores = fNames.loc[fNames['name'] == femaleName].iloc[0]['freq']
memScores = mNames.loc[mNames['name'] == maleName].iloc[0]['freq']
if femScores > memScores:
gender = 'female'
elif femScores < memScores:
gender = 'male'
return gender
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.