我是 Python 新手,我想从 postgresql 数据库中获取一列“user_name”并删除名称中的所有重音符号。Postgres 早些时候有一个名为 unaccent 的函数,但现在似乎不起作用。所以,我求助于 Python。
到目前为止,我有:
from sqlalchemy import create_engine
from pandas import DataFrame
import unidecode
engine_gear = create_engine('XYZABC')
connection = engine_gear.connect()
member = 1
result = connection.execute("select user_name from user")
df = DataFrame(result.fetchall())
df.columns = result.keys()
connection.close()
df['n'] = df['user_name'].apply(unidecode)
当我运行这段代码时,我收到以下错误:
Traceback (most recent call last):
File "C:/Users/s/PycharmProjects/test/name_matching_test.py", line 20, in <module>
df['n'] = df['user_name'].apply(unidecode)
File "C:\Python\lib\site-packages\pandas\core\series.py", line 2355, in apply
mapped = lib.map_infer(values, f, convert=convert_dtype)
File "pandas\_libs\src\inference.pyx", line 1574, in pandas._libs.lib.map_infer (pandas\_libs\lib.c:66645)
TypeError: 'module' object is not callable
起初,我认为我应该将 user_name 列转换为字符串。所以,我使用了 df['user_name'].astype('str')。但是这样做后我仍然遇到同样的错误。
任何帮助或指导将不胜感激。
数据样本:
user_name
Linda
Alonso
TestUser1
Arjang "RJ"
XI(DAPHNE)
Ajuah-AJ
Anthony "Tony"
Joseph-Patrick
Zoë
André