Importing Relational Databases Flashcards

Importing Data in Python (Part 1)

1
Q

module for SQL engines

A

from sqlalchemy import create_engine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

creating an engine

A

engine = create_engine(‘sqlite(dbtype):///filename’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

get table names from database

A

engine.table_names()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

opening a connection

A

con = engine.connect()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

perform an SQL query

A

rs = con.execute(‘Query’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

save results of query to dataframe

A

pd.DataFrame(rs.fetchall())

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

SQL to DataFrame step by step

A
  1. import create_engine from sqlalchemy
  2. create an engine
  3. open connection
  4. perform SQL query
  5. save results to DataFrame
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Query form

A

‘SELECT ColumnA, Column B (or *) FROM Table WHERE…(optional) ORDER BY…’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

querying SQL with pandas

A

pd.read_sql_query(‘query’, engine)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

inner join

A

exploit table relations: SELECT * FROM X INNER JOIN Y on *.X = *.Y

How well did you know this?
1
Not at all
2
3
4
5
Perfectly