Skip to content

Instantly share code, notes, and snippets.

justinr922

Block or report user

Report or block justinr922

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View deck_gl_with_sliders.py
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
View streamlit_hexagon_layer
st.deck_gl_chart(layers = [{
'data': location_df.drop('timestamp', axis=1),
'type': 'HexagonLayer',
'elevationScale' : 5,
'radius' : 5,
'extruded' : True,
'opacity' : 1.0
}])
View imports.py
import pandas as pd #for creating/managing dataframes
import json as json #for reading Facebook's JSON files
import streamlit as st #for streamlit
View preview dataframe
# 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 Nov 8, 2019
Converts the time data in Facebook location data tutorial
View convert_time_data.py
# 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 Nov 8, 2019
Converts Location Column to "Latitude" and "Longitude" columns
View convert_location_column.py
# 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 Nov 8, 2019
Calls the function to read location json
View call_read_json_function.py
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 Nov 8, 2019
Reads in location data from Facebook location_history.json
View Facebook_Location_From_JSON.py
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'])
You can’t perform that action at this time.