I'm working on a Thinkful challenge. Here are the instructions:
Write a script called "database.py" to print out the cities with the July being the warmest month. Your script must:
Connect to the database Create the cities and weather tables (HINT: first pass the statement DROP TABLE IF EXISTS ; to remove the table before you execute the CREATE TABLE ... statement) Insert data into the two tables Join the data together Load into a pandas DataFrame
Here is the error
Aschs-MacBook-Air:dbs aschharwood$ python database.py
File "database.py", line 20
cols = [desc[0] for desc in cur.description]
^
IndentationError: unexpected indent
Here is the code:
import sqlite3 as lite
# Here you connect to the database. The `connect()` method returns a connection object.
con = lite.connect('get_started.db')
with con:
cur = con.cursor()
cur.execute("DROP TABLE IF EXISTS cities")
cur.execute("DROP TABLE IF EXISTS weather")
cur.execute("CREATE TABLE cities (name text, state text)")
cur.execute("CREATE TABLE weather (city text, year integer, warm_month text, cold_month text)")
cur.execute("INSERT INTO cities VALUES('Washington', 'DC')")
cur.execute("INSERT INTO cities VALUES('Houston', 'TX')")
cur.execute("INSERT INTO weather VALUES('Washington', 2013, 'July', 'January',)")
cur.execute("INSERT INTO weather VALUES('Houston', 2013, 'July', 'January',)")
cur.execute("SELECT * FROM cities LEFT OUTER JOIN weather ON name = city")
rows = cur.fetchall() #grabbing all the rows
cols = [desc[0] for desc in cur.description]
df = pd.DataFrame(rows, columns=cols)
print(df)
What am I doing wrong?
Your help is much appreciated!!!