/
superstore notebook.sql
59 lines (41 loc) · 1.28 KB
/
superstore notebook.sql
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
-- Databricks notebook source
-- MAGIC %python
-- MAGIC dbutils.fs.mount(
-- MAGIC source="wasbs://raw@blobstoragesuperstore.blob.core.windows.net",
-- MAGIC mount_point= "/mnt/raw",
-- MAGIC extra_configs={"fs.azure.account.key.blobstoragesuperstore.blob.core.windows.net":"ACCESS_KEY"}
-- MAGIC )
-- COMMAND ----------
-- MAGIC %python
-- MAGIC from pyspark.sql.functions import *
-- MAGIC import urllib
-- MAGIC
-- MAGIC df= spark.read.format("csv") \
-- MAGIC .options(header= True) \
-- MAGIC .options(delimiter = ",") \
-- MAGIC .options(inferSchema = True) \
-- MAGIC .load("/mnt/raw/superstore.csv")
-- COMMAND ----------
-- MAGIC %python
-- MAGIC display(df)
-- COMMAND ----------
-- MAGIC %python
-- MAGIC df.write.mode("overwrite").saveAsTable("superstore")
-- COMMAND ----------
-- MAGIC %python
-- MAGIC df = df.withColumnRenamed("Product_ ID","Product_ID")
-- MAGIC df = df.withColumnRenamed("Ship _Date","Ship_Date")
-- COMMAND ----------
-- MAGIC %python
-- MAGIC df.columns
-- COMMAND ----------
-- MAGIC %python
-- MAGIC df.write.mode("overwrite").saveAsTable("superstore")
-- COMMAND ----------
select * from superstore
-- COMMAND ----------
select sum(Profit),city from superstore
group by 2
-- COMMAND ----------
select sum(Sales),Region from superstore
group by 2