Skip to content

Question: Query the "Employees" database and get the names and salaries of all current employees past 2022

Spinner
DataFrameas
df
variable
SELECT first_name, last_name, salary
FROM employees.employees
JOIN employees.salaries
ON employees.employees.emp_no = employees.salaries.emp_no
WHERE to_date > '2022-01-01';

Question: Query the "Bicycle Sales" database and get a detailed overview of all bicycles in stock

Spinner
DataFrameas
df
variable
SELECT *
FROM production.products
JOIN production.stocks
ON production.products.product_id = production.stocks.product_id

Question: Query the "Unicorn Companies" database and join the companies name with the funding and valuation

Note: I had to change the sentence otherwise it wouldn't join properly...

Spinner
DataFrameas
df
variable
SELECT companies.company, funding.valuation, funding.funding
FROM companies
JOIN funding
ON companies.company_id = funding.company_id

Question: Create a map pointing to the Eiffel tower

# Import the necessary libraries
import folium

# Create a map object
m = folium.Map(location=[48.8584, 2.2945], zoom_start=15)

# Add a marker for the Eiffel Tower
folium.Marker(location=[48.8584, 2.2945], popup='Eiffel Tower').add_to(m)

# Display the map
m

Question: Build a classification model with a sample dataset from the internet

[2]
# Import necessary libraries
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score

# Load the dataset
url = 'https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv'
df = pd.read_csv(url)

# Preprocess the data
X = df[['Pclass', 'Sex', 'Age', 'Fare']]
y = df['Survived']
X['Sex'] = X['Sex'].map({'male': 0, 'female': 1})
X['Age'].fillna(X['Age'].mean(), inplace=True)
X['Fare'].fillna(X['Fare'].mean(), inplace=True)

# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Scale the features
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)

# Train the model
model = LogisticRegression()
model.fit(X_train_scaled, y_train)

# Make predictions
y_pred = model.predict(X_test_scaled)

# Calculate accuracy
accuracy = accuracy_score(y_test, y_pred)
accuracy

Question: Download yfinance data for consumer technology companies and show them on a plotly chart

# Import necessary libraries
import yfinance as yf
import plotly.graph_objects as go

# Define the list of consumer technology companies
companies = ['AAPL', 'AMZN', 'FB', 'GOOGL', 'MSFT']

# Download the stock data
data = yf.download(companies, start='2021-01-01', end='2021-12-31')

# Create a plotly figure
fig = go.Figure()

# Add traces for each company
for company in companies:
    fig.add_trace(go.Scatter(x=data.index, y=data['Close'][company], name=company))

# Set the layout
fig.update_layout(title='Stock Prices of Consumer Technology Companies', xaxis_title='Date', yaxis_title='Price')

# Show the plot
fig.show()

============================= R kernel =============================

Question: Create a map pointing to the Eiffel tower

# Import the necessary libraries
library(leaflet)

# Create a map
map <- leaflet() %>%
  addTiles() %>%
  setView(lng = 2.2945, lat = 48.8584, zoom = 15) %>%
  addMarkers(lng = 2.2945, lat = 48.8584, popup = 'Eiffel Tower')

# Display the map
map