This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
location_df = read_json('location_history.json') | |
#Preview first 5 rows of dataframe | |
location_df.head() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd #for creating/managing dataframes | |
import json as json #for reading Facebook's JSON files | |
import streamlit as st #for streamlit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
st.deck_gl_chart(layers = [{ | |
'data': location_df.drop('timestamp', axis=1), | |
'type': 'HexagonLayer', | |
'elevationScale' : 5, | |
'radius' : 5, | |
'extruded' : True, | |
'opacity' : 1.0 | |
}]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |