Working with seaborn Python library: visualizing foot traffic based on big data of MAC addresses

  1. Split the time code to know hourly data. For example, since the first number of string ‘01:23:45’ split by colon delimiter would give ‘01’, any row of data where time field has starting with ‘01’ would be data from 1 am.
  2. Add MAC addresses to an array as the script runs through.
  3. Then, once the hour section of time changes, count number of elements in MAC addresses array, and map this number to the past hour in a dictionary.
  4. Empty the MAC addresses array.
  5. Repeat.
import numpy as np
import seaborn as sns
import pandas as pd
import netaddr
from matplotlib import pyplot as plt
import csv
import re

times = []
uniqueMACcount = []
currentcount = '0'
uniqueMAC = []


#convert the times
def split_by_hour(h):
h = re.split('[:]', h)
return h[0]


with open("seaborn.csv") as f:
reader = csv.reader(f)
next(reader) # skip header
data = [r for r in reader]


for element in data:
if currentcount == split_by_hour(element[1]):
if element[2] not in uniqueMAC:
try:
if (netaddr.EUI(element[2]).words[0] & 0b10) == 0 and (netaddr.EUI(element[2]).words[0] & 0b01) == 0:
uniqueMAC.append(element[2])
except (netaddr.core.AddrFormatError):
pass


if currentcount != split_by_hour(element[1]):
times.append(currentcount)
uniqueMACcount.append(len(uniqueMAC))
currentcount = split_by_hour(element[1])
uniqueMAC = []

times.append('19')
uniqueMACcount.append(len(uniqueMAC))

times = list(map(int, times))

df = pd.DataFrame(dict(hour=times, count=uniqueMACcount))
print(df.head(15))
sns_plot = sns.factorplot("hour","count", data=df,kind="bar",size=6,aspect=2,legend_out=False)
sns_plot.savefig("output.png")

--

--

--

r&d blog on architecture, software engineering and inspirations

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Task 2: Automated Web Development and Testing using Jenkins

Design Problems with Major Software

BirbSwap Audit Updates

Solving a Rubik’s Cube Using Graph Theory

Android: Continuous Integration with Travis CI

CS 371g Summer 2020: Yin Deng

Ansible and using a Bastion server to AWS EC2 instances

LeetCode #1365 “How Many Numbers Are Smaller Than the Current Number”

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
stine

stine

r&d blog on architecture, software engineering and inspirations

More from Medium

Working of k-fold cross validation

Employees Attrition Analysis — #DS001

Dealing with outliers in dataset(Python).

An introduction to Meaning of Data