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
*/Head.js*/ | |
import React from 'react'; | |
const head = (props) => { | |
return( | |
<p>I'm {props.name}.Welcome! </p> | |
) | |
} |
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
/*Register.js*/ | |
import React from 'react'; | |
import PropTypes from 'prop-types'; | |
import classNames from 'classnames'; | |
import { withStyles } from '@material-ui/core/styles'; | |
import MenuItem from '@material-ui/core/MenuItem'; | |
import Head from './Head' | |
import TextField from '@material-ui/core/TextField'; |
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
def perform_bernoulli_trials(n, p): | |
#Perform n Bernoulli trials with success probability p and return number of successes. | |
# Initialize number of successes: n_success | |
n_success = 0 | |
# Perform trials | |
for i in range(n): | |
# Choose random number between zero and one: random_number | |
random_number = np.random.random() | |
# If less than p, it's a success so add one to n_success | |
if random_number<p: |
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
from tweepy import OAuthHandler | |
from tweepy import API | |
# Consumer key authentication(consumer_key,consumer_secret can be collected from our twitter developer profile) | |
auth = OAuthHandler(consumer_key, consumer_secret) | |
# Access key authentication(access_token,access_token_secret can be collected from our twitter developer profile) | |
auth.set_access_token(access_token, access_token_secret) | |
# Set up the API with the authentication handler |
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
from tweepy import Stream | |
# Set up words to track | |
keywords_to_track = ['#javascript','#python'] | |
# Instantiate the SListener object | |
listen = SListener(api) | |
# Instantiate the Stream object | |
stream = Stream(auth, listen) |
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
tweets = [] | |
files = list(glob.iglob('/content/tweets.json')) | |
for f in files: | |
fh = open(f, 'r', encoding = 'utf-8') | |
tweets_json = fh.read().split("\n") | |
## remove empty lines | |
tweets_json = list(filter(len, tweets_json)) | |
## parse each tweet |
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
def check_word_in_tweet(word, data): | |
"""Checks if a word is in a Twitter dataset's text. | |
Checks text and extended tweet (140+ character tweets) for tweets, | |
retweets and quoted tweets. | |
Returns a logical pandas Series. | |
""" | |
contains_column = data['text'].str.contains(word, case = False) | |
contains_column |= data['extended_tweet-full_text'].str.contains(word, case = False) | |
contains_column |= data['quoted_status-text'].str.contains(word, case = False) | |
contains_column |= data['retweeted_status-text'].str.contains(word, case = False) |
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
# Print created_at to see the original format of datetime in Twitter data | |
print(df_tweet['created_at'].head()) | |
# Convert the created_at column to np.datetime object | |
df_tweet['created_at'] = pd.to_datetime(df_tweet['created_at']) | |
# Print created_at to see new format | |
print(df_tweet['created_at'].head()) | |
# Set the index of df_tweet to created_at |
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 matplotlib.pyplot as plt | |
# Average of python column by day | |
mean_python = df_tweet['python'].resample('1 min').mean() | |
# Average of js column by day | |
mean_js = df_tweet['js'].resample('1 min').mean() | |
# Plot mean python/js by day | |
plt.plot(mean_python.index.minute, mean_python, color = 'green') | |
plt.plot(mean_js.index.minute, mean_js, color = 'blue') |
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
def calculateCentroid(place): | |
""" Calculates the centroid from a bounding box.""" | |
# Obtain the coordinates from the bounding box. | |
coordinates = place['bounding_box']['coordinates'][0] | |
longs = np.unique( [x[0] for x in coordinates] ) | |
lats = np.unique( [x[1] for x in coordinates] ) | |
if len(longs) == 1 and len(lats) == 1: | |
# return a single coordinate |
OlderNewer