This file contains hidden or 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 json | |
| from tulip_api import TulipAPI,TulipTable, CachedTulipTable | |
| import pandas as pd | |
| import numpy as np | |
| from datetime import datetime | |
| import os | |
| def lambda_handler(event, context): | |
| # instance url, api key, and api secret are stored as environment variables | |
| instance_url = os.getenv('instance') |
This file contains hidden or 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 seaborn as sns | |
| import matplotlib.pyplot as plt | |
| import pandas as pd | |
| fig, ax = plt.subplots(figsize=(15, 5)) | |
| sns.lineplot(ax=ax, data=df_chapters, hue='book', linewidth=3, x='chapter', y='weighted_score') | |
| plt.xlabel("Chapter #") | |
| plt.ylabel("Avg. Sentiment") | |
| plt.title("Gospels Analysis - Avg. Sentiment by Chapter\n(Higher Values are Positive Sentiment; Lower Values are Negative Sentiment)") | |
| plt.show(fig) |
This file contains hidden or 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 | |
| import numpy as np | |
| from transformers import pipeline | |
| def sentiment_score_weight(sentiment): | |
| label = sentiment['label'] | |
| score = float(sentiment['score']) | |
| label_value = 1 if label == 'POSITIVE' else -1 | |
| weighted_score = label_value*score | |
| return weighted_score |
This file contains hidden or 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 book_split(text): | |
| book = text.split(' ') | |
| return ' '.join(book[0:len(book)-1]) | |
| def chapter_split(text): | |
| reference_list = text.split(' ') | |
| chapter_verse = reference_list[-1].split(':') | |
| return int(chapter_verse[0]) |
This file contains hidden or 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
| bible_url = 'https://bereanbible.com/bsb.txt' | |
| with open('./data/bereanbible.txt', 'r') as f: | |
| text = f.read() | |
| response = requests.get(bible_url) | |
| raw_bible = response.text | |
| bible_list = raw_bible.splitlines() | |
| bible_array = np.array([item.split('\t') for item in bible_list]) | |
| def printable_string(text): | |
| filtered_string = ''.join(s for s in text if s in string.printable) |
This file contains hidden or 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 sentiment_pipeline(text, model): | |
| sentiment = model(text) | |
| return pd.Series([sentiment[0]['label'], sentiment[0]['score']]) | |
| model = pipeline("sentiment-analysis") | |
| df[['sentiment_label','sentiment_score']]=df['prompt'].apply(lambda x: sentiment_pipeline(text=x,model=model)) |
This file contains hidden or 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 sklearn.model_selection import train_test_split | |
| def split_data(df: pd.DataFrame, parameters: Dict) -> Tuple: | |
| """Splits data into features and targets training and test sets. | |
| Args: | |
| data: Data containing features and target. | |
| parameters: Parameters defined in parameters/data_science.yml. | |
| Returns: | |
| Split data. |
This file contains hidden or 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
| %%writefile exploratory_data_analysis.py | |
| import pandas as pd | |
| import numpy as np | |
| import seaborn as sns | |
| ## Python Code Here |
This file contains hidden or 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
| SELECT | |
| geolocation.lat, | |
| geolocation.lon, | |
| geolocation.alt, | |
| system.timestamp as "event_time" | |
| INTO | |
| [sql] | |
| FROM | |
| [iot] |
This file contains hidden or 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
| SELECT | |
| TRY_CAST(decoded.payload.TempC_SHT AS float) AS InternalTemp_C, | |
| (TRY_CAST(decoded.payload.TempC_SHT AS float) * 9/5) + 32 AS InternalTemp_F, | |
| TRY_CAST(decoded.payload.Hum_SHT AS float) AS InternalHum, | |
| TRY_CAST(decoded.payload.TempC_DS AS float) AS ExternalTemp_C, | |
| (TRY_CAST(decoded.payload.TempC_DS AS float) * 9/5) + 32 AS ExternalTemp_F, | |
| TRY_CAST(EventProcessedUtcTime AS datetime) AS ProcessTimeUTC, | |
| TRY_CAST(EventEnqueuedUtcTime AS datetime) AS QueueTimeUTC, | |
| EventProcessedUtcTime AS ProcessedTimeRaw, | |
| EventEnqueuedUtcTime AS EnqueuedTimeRaw, |
NewerOlder