I have a sqlite file that I am trying to extract some data from, I established the connection and selected the columns that I wanted to save in a csv but when it saves it returns column with the column name repeated. The number of rows is the same as the data available (which I was able to see when I selected all columns).
#code:
file = sqlite_file
def SQLiteQuery(query, file):
con = sqlite3.connect(file)
return pd.read_sql_query(query, con)
#I used this to see the available db tables
query = "SELECT * FROM sqlite_master"
table_names = SQLiteQuery(query, file)
#Selecting specific columns
table = table_name.loc[15, 'name']
print(table)
query = (f"SELECT 'column_name1', 'column_name2' FROM '{table}';")
df = SQLiteQuery(query, file)
save_to = 'path_to_folder/filename.csv'
df.to_csv(save_to)
result in csv:
1 column_name1 column_name2
2 column_name1 column_name2
3 column_name1 column_name2
4 column_name1 column_name2
...