0

pd.read_sql(sql) If sql has two columns of the same field, the result is only one column of fields

pd.read_sql() dont work ?

import pandas as pd

sql = "select name, name, age from table;"
df = pd.read_sql(sql, con)

print(df.columns) 
# name, age

it work

with conn.cursor() as a:
    a.execute(sql)
    lines = a.fetchall()
df = pd.DataFrame(lines)
  • yes, Pandas can have only unique names of the columns, try using an alias for one of the duplicates columns, such as `select name, name AS name2, age from table;` – Zero Jul 20 '23 at 07:38

0 Answers0