我正在使用性别猜测器库从名字中猜测性别。
import gender_guesser.detector as gender
d = gender.Detector()
print(d.get_gender(u"Bob"))
male
gen = ['Alice', 'Bob', 'Kattie', "Jean", "Gabriel"]
female
male
female
male
male
但是当我尝试遍历pandas数据框时,我得到的输出为未知
for name in df1['first_name'].iteritems():
print(d.get_gender(name))
答案 0 :(得分:0)
一种方法是使用地图。
for line in file_read:
try:
print(eval(line), file=file_write)
except NameError:
print("Bad Expression", file=file_write)
它将创建一个名为“性别”的新列。我认为应该比迭代更快。