I'm a complete newbie when it comes to Python. Using pyodbc, I've managed to connect to an instance of SQL Server Express 2008 R2 I have running locally. How do I create an array similar to a dataframe in R?
Using RODBC in R, I can easily fetch directly to a dataframe. For example, if I pull a table with 5 columns and 5 rows, I fetch the data into a dataframe with 5 columns and 5 rows.
With pyodbc, I fetch what appears to be all the cells consecutively like this:
[('2013 Q4', 'An', 'Ta', 'Mono', 'Consumer', 'Europe', '2014 Q3', '2014', 'Q3', 'Transfer', 1.0), ('2013 Q4', 'An', 'Ta', 'Mono', 'Consumer', 'Europe', '2014 Q4', '2014', 'Q4', 'Transfer', 1.0)]
This is the code I used in Python 2.7.3:
cursor.execute("""select *
from table1
""")
row = cursor.fetchall()
print row
Can someone direct me to some reference material online? (I'm having no luck with google.) Is it even possible to do what I'm asking with Python? In R, reading data from SQL tables is trivial. I'm getting the impression that I have to process each fetched line with Python???