In [1]:
import pandas as pd
In [2]:
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
In [3]:
df = pd.read_csv('data3781.csv', index_col=0, parse_dates=True)
In [4]:
df_ts=df.index
df_ts = pd.to_datetime(df_ts, utc=True)
df_ts = df_ts.tz_localize('UTC').tz_convert('Asia/Tokyo').tz_localize(None)
df.index = df_ts
In [5]:
pd.options.display.max_rows = 10
In [6]:
df
Out[6]:
temperature humidity pressure temperature2 humidity2 pressure2 Unnamed: 7 Unnamed: 8
Created
2018-08-27 23:41:17.232 NaN NaN NaN 27.62 60.93 1013.53 NaN NaN
2018-08-27 23:43:20.090 28.41 56.49 1013.35 NaN NaN NaN NaN NaN
2018-08-27 23:46:17.972 NaN NaN NaN 27.74 65.91 1013.61 NaN NaN
2018-08-27 23:48:21.320 28.11 54.09 1013.21 NaN NaN NaN NaN NaN
2018-08-27 23:51:18.548 NaN NaN NaN 27.63 65.47 1013.50 NaN NaN
... ... ... ... ... ... ... ... ...
2018-09-06 19:18:45.867 NaN NaN NaN 33.31 56.82 1009.36 NaN NaN
2018-09-06 19:22:51.463 32.70 60.12 1009.13 NaN NaN NaN NaN NaN
2018-09-06 19:23:47.119 NaN NaN NaN 33.30 56.88 1009.50 NaN NaN
2018-09-06 19:27:52.712 32.69 60.11 1009.24 NaN NaN NaN NaN NaN
2018-09-06 19:28:47.836 NaN NaN NaN 33.25 57.06 1009.58 NaN NaN

5569 rows × 8 columns

In [7]:
df1 = df.dropna(subset=['temperature'])
df2 = df.dropna(subset=['temperature2'])
df1.drop(columns=['humidity','pressure','temperature2','humidity2', 'pressure2', 'Unnamed: 7','Unnamed: 8'],axis=1, inplace=True)
df2.drop(columns=['temperature', 'humidity', 'pressure','humidity2', 'pressure2','Unnamed: 7','Unnamed: 8'], axis=1, inplace=True)
/opt/conda/lib/python3.6/site-packages/pandas/core/frame.py:3697: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  errors=errors)
In [8]:
df1
Out[8]:
temperature
Created
2018-08-27 23:43:20.090 28.41
2018-08-27 23:48:21.320 28.11
2018-08-27 23:53:22.970 27.85
2018-08-27 23:58:24.646 27.74
2018-08-28 00:03:26.288 27.56
... ...
2018-09-06 19:07:47.219 32.77
2018-09-06 19:12:48.697 32.75
2018-09-06 19:17:50.086 32.73
2018-09-06 19:22:51.463 32.70
2018-09-06 19:27:52.712 32.69

2771 rows × 1 columns

In [9]:
df2
Out[9]:
temperature2
Created
2018-08-27 23:41:17.232 27.62
2018-08-27 23:46:17.972 27.74
2018-08-27 23:51:18.548 27.63
2018-08-27 23:56:19.566 27.64
2018-08-28 00:01:21.237 27.71
... ...
2018-09-06 19:08:46.278 33.35
2018-09-06 19:13:47.080 33.34
2018-09-06 19:18:45.867 33.31
2018-09-06 19:23:47.119 33.30
2018-09-06 19:28:47.836 33.25

2798 rows × 1 columns

In [10]:
##plt.xkcd()
fig, ax = plt.subplots(figsize=(10,8))
ax.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d\n%H:%M'))
ax.plot(df1['2018-08-28 02:00':'2018-08-29 00:00'])
ax.plot(df2['2018-08-28 02:00':'2018-08-29 00:00'], 'r')
plt.show()
In [11]:
fig, ax = plt.subplots(figsize=(10,8))
ax.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d\n%H:%M'))
ax.plot(df1['2018-09-02 18:00':'2018-09-03 18:00'])
ax.plot(df2['2018-09-02 18:00':'2018-09-03 18:00'], 'r')
plt.show()
In [12]:
fig, ax = plt.subplots(figsize=(10,8))
ax.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d\n%H:%M'))
ax.plot(df1['2018-08-31 00:00':'2018-08-31 23:00'])
ax.plot(df2['2018-08-31 00:00':'2018-08-31 23:00'], 'r')
plt.show()
In [13]:
import ambient
In [14]:
am = ambient.Ambient(6128, '', 'xxxxxxxx')
ec = am.read()
ec[:3]
Out[14]:
[{'d1': 6.425, 'd2': 1.037609554085524, 'created': '2018-09-02T07:41:07.136Z'},
 {'d1': 6.415, 'd2': 1.037716420754328, 'created': '2018-09-02T07:42:06.354Z'},
 {'d1': 6.415, 'd2': 1.03782318742313, 'created': '2018-09-02T07:43:06.603Z'}]
In [15]:
df3 = pd.DataFrame(ec)
df3.head(3)
Out[15]:
created d1 d2
0 2018-09-02T07:41:07.136Z 6.425 1.037610
1 2018-09-02T07:42:06.354Z 6.415 1.037716
2 2018-09-02T07:43:06.603Z 6.415 1.037823
In [16]:
df3['created'] = pd.to_datetime(list(df3['created'])).tz_localize('GMT').tz_convert('Asia/Tokyo').tz_localize(None)
df3 = df3.set_index('created')
df3.drop(columns=['d2'],axis=1, inplace=True)
In [17]:
fig, ax1 = plt.subplots(figsize=(20,16))
s = '2018-09-02 18:00'
e= '2018-09-03 18:00'
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d\n%H:%M'))
ax1.plot(df1[s:e])
ax1.plot(df2[s:e], 'r')
ax2 = ax1.twinx()
ax2.plot(df3[s:e], 'g',linewidth=1)
plt.show()
In [18]:
df3
Out[18]:
d1
created
2018-09-02 16:41:07.136 6.425
2018-09-02 16:42:06.354 6.415
2018-09-02 16:43:06.603 6.415
2018-09-02 16:44:06.821 6.435
2018-09-02 16:45:07.011 6.420
... ...
2018-09-06 20:48:06.362 0.660
2018-09-06 20:49:06.614 0.640
2018-09-06 20:50:06.842 0.675
2018-09-06 20:51:07.191 0.660
2018-09-06 20:52:06.455 0.660

6000 rows × 1 columns

In [19]:
fig, ax1 = plt.subplots(figsize=(10,8))
s = '2018-09-02 18:00'
e= '2018-09-03 07:00'
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d\n%H:%M'))
ax1.plot(df1[s:e],'r')
plt.show()
In [20]:
fig, ax1 = plt.subplots(figsize=(10,8))
s = '2018-09-02 18:00'
e= '2018-09-03 07:00'
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d\n%H:%M'))
ax1.plot(df3[s:e], 'g',linewidth=1)
plt.show()
In [21]:
fig, ax1 = plt.subplots(figsize=(10,8))
s = '2018-09-02 18:00'
e= '2018-09-03 07:00'
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d\n%H:%M'))
ax1.plot(df1[s:e],'r')
ax2 = ax1.twinx()
ax2.plot(df3[s:e], 'g',linewidth=1)
plt.show()
In [22]:
fig, ax1 = plt.subplots(figsize=(10,8))
s = '2018-09-03 00:00'
e= '2018-09-03 23:00'
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d\n%H:%M'))
ax1.plot(df1[s:e],'r')
ax2 = ax1.twinx()
ax2.plot(df3[s:e], 'g',linewidth=1)
ax2.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d\n%H:%M'))
plt.show()
In [23]:
fig, ax1 = plt.subplots(figsize=(10,8))
s = '2018-09-03 00:00'
e= '2018-09-03 23:00'
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d\n%H:%M'))
ax1.plot(df1[s:e],'b')
ax1.plot(df2[s:e],'r')
ax2 = ax1.twinx()
ax2.plot(df3[s:e], 'g',linewidth=1)
ax2.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d\n%H:%M'))
plt.show()
In [24]:
fig, ax1 = plt.subplots(figsize=(10,8))
s = '2018-09-06 02:00'
e= '2018-09-06 23:00'
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d\n%H:%M'))
ax1.plot(df1[s:e],'b')
ax1.plot(df2[s:e],'r')
plt.show()
In [25]:
tokyo_180906temperature = [('2018-09-06 01:00:00', 26.7	), ('2018-09-06 02:00:00', 26.3	),('2018-09-06 03:00:00', 25.9	),
                          ('2018-09-06 04:00:00', 26.0	),('2018-09-06 05:00:00', 25.4	),('2018-09-06 06:00:00', 25.6	),
                          ('2018-09-06 07:00:00', 26.0	),('2018-09-06 08:00:00', 26.6	),('2018-09-06 09:00:00', 28.6		),
                          ('2018-09-06 10:00:00', 29.5	),('2018-09-06 11:00:00', 29.2	),('2018-09-06 12:00:00', 31.1	),
                          ('2018-09-06 13:00:00', 29.4	),('2018-09-06 14:00:00', 28.8	),('2018-09-06 15:00:00', 28.9	),
                          ('2018-09-06 16:00:00', 28.5	),('2018-09-06 17:00:00', 28.5	),('2018-09-06 18:00:00', 28.0	),
                          ('2018-09-06 19:00:00', 27.7	)]
df4 = pd.DataFrame(tokyo_180906temperature)
df4[0] = pd.to_datetime(list(df4[0]))
df4 = df4.set_index(0)
df4
Out[25]:
1
0
2018-09-06 01:00:00 26.7
2018-09-06 02:00:00 26.3
2018-09-06 03:00:00 25.9
2018-09-06 04:00:00 26.0
2018-09-06 05:00:00 25.4
... ...
2018-09-06 15:00:00 28.9
2018-09-06 16:00:00 28.5
2018-09-06 17:00:00 28.5
2018-09-06 18:00:00 28.0
2018-09-06 19:00:00 27.7

19 rows × 1 columns

In [26]:
fig, ax1 = plt.subplots(figsize=(10,8))
s = '2018-09-06 02:00'
e= '2018-09-06 23:00'
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d\n%H:%M'))
ax1.plot(df1[s:e],'b')
ax1.plot(df2[s:e],'r')
ax1.plot(df4,'k')
plt.show()
In [ ]: