-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_notebook.py
75 lines (51 loc) · 1.57 KB
/
test_notebook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Databricks notebook source
dbutils.widgets.text("limit", "10")
dbutils.widgets.text("data_source_url", "")
# COMMAND ----------
# MAGIC %md
# MAGIC # Download and analyse external data
# COMMAND ----------
data_source_url=dbutils.widgets.get("data_source_url")
# COMMAND ----------
# MAGIC %run ./download_dataset
# COMMAND ----------
df.describe()
# COMMAND ----------
import matplotlib.pyplot as plt
import seaborn as sns
from pyspark.sql import functions as F
limit = int(dbutils.widgets.get("limit"))
# Top 10 artists with most songs in the dataset
top_artists = df.groupBy("artist(s)_name").count().orderBy(F.desc("count")).limit(limit).toPandas()
# Plot
plt.figure(figsize=(12, 6))
sns.barplot(x=top_artists["artist(s)_name"], y=top_artists["count"], palette='viridis')
plt.xlabel('Number of Songs')
plt.ylabel('Artist(s) Name')
plt.title('Top 10 Artists with Most Songs')
plt.show()
top_artists
# COMMAND ----------
# MAGIC %md
# MAGIC # Analyse data already in databricks
# COMMAND ----------
# MAGIC %sql
# MAGIC select * from samples.nyctaxi.trips
# MAGIC order by trip_distance desc
# COMMAND ----------
limit = int(dbutils.widgets.get("limit"))
df = _sqldf.limit(limit)
# COMMAND ----------
import matplotlib.pyplot as plt
import seaborn as sns
from pyspark.sql import functions as F
limit = int(dbutils.widgets.get("limit"))
df = _sqldf.select("trip_distance").toPandas()
# Plot
plt.figure(figsize=(12, 6))
sns.histplot(data=df, palette='viridis')
plt.xlabel('Trip distance')
plt.ylabel('# of trups')
plt.title('Distribution of trips')
plt.show()
# COMMAND ----------