Today I continued working on SQL…
I learned:
To count up certain values or the number of variables in a column, one can use COUNT(*), and attach “AS new_category_name” to create a new category with the count! This was useful in the example data of Nobel laureates to count how many prizes each country won. It’s also important to use “GROUP BY category_name” to determine how to group the counted variable.
This feels like the first real step in data analysis. I can now take the data and view it in different ways which allows me to put in some creativity. Fun!
I am still confused on:
When importing a database with the fancy code my friend setup…
def db_connect(db_name):
try:
conn = sqlite3.connect(db_name)
print(“Connection established”)
except Error:
print(Error, “Cannot create connection to database”)
return conn
conn = db_connect(“data/nobel.db”)
… I will sometimes get the error “local variable ‘conn’ referenced before assignment’. But this sometimes doesn’t happen and the code works properly. I’m not sure what’s the differentiating variable here… hmph.
Anywho progress is exciting! I’ve been in line to get this COVID test for the past 3 hours so it’s been nice to be productive coding 🙂