我正在尝试查询多个sql表,并将它们存储为pandas数据框。
cur = conn.cursor()
cur.execute("select relname from pg_class where relkind='r' and relname !~ '^(pg_|sql_)';")
tables_df = cur.fetchall()
##table_name_list = tables_df.table_name
select_template = ' SELECT * FROM {table_name}'
frames_dict = {}
for tname in tables_df :
query = select_template.formate(table_name = tname)
frames_dict [tname] = pd.read_sql ( query , conn)
但是它给了我
AttributeError: 'str' object has no attribute 'formate'
在线
query = select_template.formate(table_name = tname)
根据您的错误,您似乎有一个错字字格式:
AttributeError: 'str' object has no attribute 'formate'
尝试
query = select_template.format(table_name = tname)