-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathsqlalchemy_updating_database_data.py
More file actions
63 lines (41 loc) · 1.65 KB
/
sqlalchemy_updating_database_data.py
File metadata and controls
63 lines (41 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from sqlalchemy import MetaData, Table, create_engine, select, func
def n():
""" Function to add a number to each output """
count = 0
for i in str(count):
print(str(i) + '\n')
count += 1
metadata = MetaData()
engine = create_engine('mysql+pymysql://student:datacamp@courses.csrrinzqubik.us-east-1.rds.amazonaws.com:3306/census')
connection = engine.connect()
census = Table('census', metadata, autoload=True, autoload_with=engine)
engine1 = create_engine('sqlite:///employees.sqlite')
connection = engine1.connect()
employees = Table('employees', metadata, autoload=True, autoload_with=engine1)
print(employees.columns.keys())
print(census.columns.keys())
from sqlalchemy import update, Table, Column, String, Integer, Float, Boolean
# Define a new table with a name, count, amount, and valid column: data
data = Table('extra_employees', metadata,
Column('name', String(255)),
Column('id', Integer()),
Column('amount', Float()),
Column('valid', Boolean())
)
# Use the metadata to create the table
metadata.create_all(engine1)
"""
not retreving state_fact data
stmt = update(state_fact).values(notes='The Wild West')
stmt = stmt.where(state_fact.columns.census_name_region == 'West')
results = connnection.execute(stmt)
print(results.rowcount)
fips_stmt = select([state_fact.columns.name])
fips_stmt = fips_stmt.where(state_fact.columns.fips_state == flat_census.columns.fips_code)
update_stmt = update(flat_census).values(state_name=fips_stmt)
results = connection.execute(update_stmt)
print(results.rowcount)
"""