Skip to content

Instantly share code, notes, and snippets.

@vilterp
Last active August 29, 2015 14:04
Show Gist options
  • Save vilterp/bb820e9ced0b65a31f73 to your computer and use it in GitHub Desktop.
Save vilterp/bb820e9ced0b65a31f73 to your computer and use it in GitHub Desktop.
def write_to_db(conn, file):
df = pd.read_csv(file, parse_dates=[1])
df2 = df.rename(columns={'dataid': 'house_id', 'use': 'total_energy'})
df3 = df2.fillna(0)
df3.utc = df3.utc.map(str)
sql.write_frame(df3, con=conn, name='readings', if_exists='append', flavor='mysql')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment