Analyzing IoT Data in Python Chapter1
Analyzing IoT Data in Python Chapter1
Analyzing IoT Data in Python Chapter1
data
A N A LY Z I N G I OT D ATA I N P Y T H O N
Matthias Voppichler
IT Developer
Course overview
Collect and analyze IoT data
Gather data
API Endpoints
Data Streams
Visualize data
Combine datasets
Detect patterns
plain text
binary data
XML
Proprietary protocols
API endpoints
print(pd.DataFrame(r.json()).head())
timestamp value
0 1536924000000 22.3
1 1536924600000 22.8
2 1536925200000 23.3
print(df_env.head())
timestamp value
0 2018-09-14 11:20:00 22.3
1 2018-09-14 11:30:00 22.8
2 2018-09-14 11:40:00 23.3
print(df_env.dtypes)
timestamp datetime64[ns]
value float64
dtype: object
Matthias Voppichler
IT Developer
Store data to disk
Reasons to store IoT Data
Reproducible results
Training ML Models
!cat data.json
[{'timestamp': 1536924000000, 'value': 22.3},
{'timestamp': 1536924600000, 'value': 22.8},
{'timestamp': 1536925200000, 'value': 23.3},
{'timestamp': 1536925800000, 'value': 23.6},
{'timestamp': 1536926400000, 'value': 23.5}]
import pandas as pd
df_env = pd.read_json("data.json")
From CSV le
import pandas as pd
df_env = pd.read_csv("data.csv")
df_env.head()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 13085 entries, 0 to 13085
Data columns (total 5 columns):
pressure 13085 non-null float64
humidity 13085 non-null float64
sunshine 13083 non-null float64
temperature 13059 non-null float64
timestamp 13085 non-null datetime64[ns]
dtypes: datetime64[ns](1), float64(6)
memory usage: 1.4 MB
Matthias Voppichler
IT Developer
What is a Data Stream
Constant stream of Data
Examples
Twitter messages
Video streams
Examples
Twitter messages
Video streams
Publish / subscribe
Small footprint
Client:
Connects to a Broker
Publishes data
Subscribes to topics
print(f"{msg.topic}, {msg.payload}")
Output:
print(f"{message.topic} : {message.payload}")
Arguments
subscribe.callback(on_message,
topics="datacamp/roomtemp",
hostname="test.mosquitto.org")
subscribe.callback(on_message,
topics="datacamp/roomtemp",
hostname="test.mosquitto.org")