Answers for "can pandas fetch data from sql"

SQL
-1

can pandas fetch data from sql

import pandas as pd
import sqlite3

con = sqlite3.connect("data/portal_mammals.sqlite")

# Load the data into a DataFrame
surveys_df = pd.read_sql_query("SELECT * from surveys", con)

# Select only data for 2002
surveys2002 = surveys_df[surveys_df.year == 2002]

# Write the new DataFrame to a new SQLite table
surveys2002.to_sql("surveys2002", con, if_exists="replace")

con.close()
Posted by: Guest on January-05-2022

Code answers related to "SQL"

Browse Popular Code Answers by Language