Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

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()
Source by datacarpentry.org #
 
PREVIOUS NEXT
Tagged: #pandas #fetch #data #sql
ADD COMMENT
Topic
Name
9+1 =