0

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!!!

Aschharwood
  • 391
  • 1
  • 4
  • 16
  • The IndentationError might be due to mixing tabs and spaces. Run `python -t database.py`. The `-t` flag tells python to warn if the source file mixes tabs and spaces for indentation. – unutbu Apr 18 '16 at 22:13
  • If it turns out that the IndentationError is due to mixing tabs and spaces, you could use [autope8 or reindent.py](http://stackoverflow.com/a/2625361/190597) to convert the tabs to spaces. – unutbu Apr 18 '16 at 22:17
  • This is definitely the issue. Seemed to have happened when I did the copy and paste from one .py file to another. Thanks! – Aschharwood Apr 19 '16 at 02:07

1 Answers1

0

So it turns out that this was a copy paste issue in my text editor, Sublime Text. I copied some code from one file to another. And while it did not look like there was an indent issue, the text editor seemed to be reading it as so.

Aschharwood
  • 391
  • 1
  • 4
  • 16