generalize_names: 将名称转换为通用格式
一个将姓名转换为一般格式的函数<last_name><separator><firstname letter(s)>
(全部为小写)。
from mlxtend.text import generalize_names
概述
一个将名字转换为通用格式的函数 <last_name><separator><firstname letter(s)>
(全部小写),这在从不同来源收集数据并希望根据姓名标识符进行比较或合并时非常有用。例如,如果姓名存储在 pandas 的 DataFrame
列中,可以使用 apply 函数来通用化姓名:df['name'] = df['name'].apply(generalize_names)
参考文献
- -
示例 1 - 默认值
from mlxtend.text import generalize_names
generalize_names('Pozo, José Ángel')
'pozo j'
generalize_names('José Pozo')
'pozo j'
generalize_names('José Ángel Pozo')
'pozo j'
示例 2 - 可选参数
from mlxtend.text import generalize_names
generalize_names("Eto'o, Samuel", firstname_output_letters=2)
'etoo sa'
generalize_names("Eto'o, Samuel", firstname_output_letters=0)
'etoo'
generalize_names("Eto'o, Samuel", output_sep=', ')
'etoo, s'
API
generalize_names(name, output_sep=' ', firstname_output_letters=1)
Generalize a person's first and last name.
Returns a person's name in the format
<last_name><separator><firstname letter(s)> (all lowercase)
Parameters
-
name
:str
Name of the player
-
output_sep
:str
(default: ' ')String for separating last name and first name in the output.
-
firstname_output_letters
:int
Number of letters in the abbreviated first name.
Returns
-
gen_name
:str
The generalized name.
Examples
For usage examples, please see https://rasbt.github.io/mlxtend/user_guide/text/generalize_names/