Skip to content

Instantly share code, notes, and snippets.

elevationScale = st.slider('Elevation Scale', min_value = 0, max_value = 50)
radius = st.slider('Radius', min_value = 1, max_value = 50)
st.deck_gl_chart(layers = [{
'data': location_data.iloc[0:num_of_points, :],
'type': 'HexagonLayer',
'elevationScale' : elevationScale,
'radius' : radius,
'extruded' : True,
'opacity' : 1.0
st.deck_gl_chart(layers = [{
'data': location_df.drop('timestamp', axis=1),
'type': 'HexagonLayer',
'elevationScale' : 5,
'radius' : 5,
'extruded' : True,
'opacity' : 1.0
}])
import pandas as pd #for creating/managing dataframes
import json as json #for reading Facebook's JSON files
import streamlit as st #for streamlit
# Read in the file using the function we wrote
location_df= read_json('location_history.json')
#Call .head() to preview the dataframe
location_df.head()
@justinr922
justinr922 / convert_time_data.py
Last active November 8, 2019 21:20
Converts the time data in Facebook location data tutorial
# We can apply Pandas.to_datetime() on the creation_timestamp
# column. The unit is 's' for "seconds since the epoch since that is
# the current time format.
location_df['timestamp'] = pd.to_datetime(location_data['creation_timestamp'], unit='s')
#And drop the old column
location_df.drop('creation_timestamp', axis=1, inplace=True)
@justinr922
justinr922 / convert_location_column.py
Last active November 8, 2019 21:09
Converts Location Column to "Latitude" and "Longitude" columns
# Each coordinate is in the form of a dictionary like so:
#
# {'latitude': 34.3, 'longitude': -89.5}
#
# So we will use list compreshension to create a new column,
# using dictionary.get(key) to access each value.
location_df['latitude'] = [value.get('latitude') for value in location_df['coordinate']]
location_df['longitude'] = [value.get('longitude') for value in location_df['coordinate']]
#And drop the old coordinate column, since we have gotten what we need out of it
@justinr922
justinr922 / call_read_json_function.py
Created November 8, 2019 20:49
Calls the function to read location json
location_df = read_json('location_history.json')
#Preview first 5 rows of dataframe
location_df.head()
@justinr922
justinr922 / Facebook_Location_From_JSON.py
Last active November 8, 2019 20:36
Reads in location data from Facebook location_history.json
import pandas as pd #for creating/managing dataframes
import json as json #for reading Facebook's JSON files
def read_json(path_to_json):
# Opens the json file in memory
with open(path_to_json, 'r', encoding='utf8') as file:
# Reads the file into a string, and then uses jsons.loads (loadstring)
# to interpret the data
data_file = json.loads(file.read())
return pd.DataFrame(data_file['location_history'])