I'm using a temperature and humidity sensor connected to a Raspberry Pi to log those in regular intervals into a sqlite3 DB with the following schema:
sqlite> .schema
CREATE TABLE sensor_data (tdate DATE, ttime TIME, temperature NUMERIC, humidity NUMERIC);
For test purposes there are just two entries:
sqlite> SELECT * FROM sensor_data;
2017-03-02|19:04:42|19.8999996185303|51.5
2017-03-02|19:26:08|19.8999996185303|51.2000007629395
Now I'd like to analyze and plot the data using pandas:
#! /usr/bin/python
from datetime import datetime
import sqlite3
import pandas as pd
conn = sqlite3.connect('test.db')
with conn:
curs = conn.cursor()
df = pd.read_sql_query("SELECT * FROM sensor_data", conn,
parse_dates={'tdate':"%Y-%m-%d",'ttime':"%H:%M:%S"})
print(df)
conn.close()
The result:
$ ./test.py
tdate ttime temperature humidity
0 2017-03-02 1900-01-01 19:04:42 19.9 51.500000
1 2017-03-02 1900-01-01 19:26:08 19.9 51.200001
My question is:
How do I get rid of the column containing the 1900-01-01
's and then combine tdate
and ttime
into one column?
Thanks in advance!
Cheers, Lars