When you get a new dataset, one of the first things you want to do is find your summary statistics. These essential numbers tell you the basics about your data so you start off your analysis on an informed foot.
The main summary statistics are:
select * from PUBLIC.LONDON_WEATHER
SELECT * FROM (
SELECT
'TEMP' COL,
MIN(TEMP) MIN,
PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY TEMP) "25th PERCENTILE",
MEDIAN(TEMP) MEDIAN,
PERCENTILE_CONT(0.75) WITHIN GROUP (ORDER BY TEMP) "75th PERCENTILE",
MAX(TEMP) MAX,
AVG(TEMP) AVG,
MODE(TEMP) MODE,
STDDEV(TEMP) STD_DEV
FROM PUBLIC.LONDON_WEATHER
GROUP BY COL)
UNION ALL (
SELECT
'PRECIPITATION' COL,
MIN(PRECIPITATION) MIN,
PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY PRECIPITATION) "25th PERCENTILE",
MEDIAN(PRECIPITATION) MEDIAN,
PERCENTILE_CONT(0.75) WITHIN GROUP (ORDER BY PRECIPITATION) "75th PERCENTILE",
MAX(PRECIPITATION) MAX,
AVG(PRECIPITATION) AVG,
MODE(PRECIPITATION) MODE,
STDDEV(PRECIPITATION) STD_DEV
FROM PUBLIC.LONDON_WEATHER
GROUP BY COL
)
UNION ALL (
SELECT
'VISIBILITY' COL,
MIN(VISIBILITY) MIN,
PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY VISIBILITY) "25th PERCENTILE",
MEDIAN(VISIBILITY) MEDIAN,
PERCENTILE_CONT(0.75) WITHIN GROUP (ORDER BY VISIBILITY) "75th PERCENTILE",
MAX(VISIBILITY) MAX,
AVG(VISIBILITY) AVG,
MODE(VISIBILITY) MODE,
STDDEV(VISIBILITY) STD_DEV
FROM PUBLIC.LONDON_WEATHER
GROUP BY COL
)
UNION ALL (
SELECT
'WINDSPEED' COL,
MIN(WINDSPEED) MIN,
PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY WINDSPEED) "25th PERCENTILE",
MEDIAN(WINDSPEED) MEDIAN,
PERCENTILE_CONT(0.75) WITHIN GROUP (ORDER BY WINDSPEED) "75th PERCENTILE",
MAX(WINDSPEED) MAX,
AVG(WINDSPEED) AVG,
MODE(WINDSPEED) MODE,
STDDEV(WINDSPEED) STD_DEV
FROM PUBLIC.LONDON_WEATHER
GROUP BY COL
)
SELECT
'DATE' COL,
MIN(DATE) MIN,
MAX(DATE) MAX,
MODE(DATE) MODE,
COUNT(DISTINCT DATE) UNIQUE_VALUES
FROM PUBLIC.LONDON_WEATHER
GROUP BY COL
SELECT
'WEATHER' COL,
MIN(WEATHER) MIN,
MAX(WEATHER) MAX,
MODE(WEATHER) MODE,
COUNT(DISTINCT WEATHER) UNIQUE_VALUES
FROM PUBLIC.LONDON_WEATHER
GROUP BY COL
Correlation matrices let you quickly see the correlations between all the different variables.
To create them, we will make use of the CORR
SELECT * FROM
(SELECT 'TEMP' COL_1, 'PRECIPITATION' COL_2, CORR(TEMP,PRECIPITATION) CORR
FROM PUBLIC.LONDON_WEATHER) UNION ALL
(SELECT 'TEMP' COL_1, 'VISIBILITY' COL_2, CORR(TEMP,VISIBILITY) CORR
FROM PUBLIC.LONDON_WEATHER) UNION ALL
(SELECT 'TEMP' COL_1, 'WINDSPEED' COL_2, CORR(TEMP,WINDSPEED) CORR
FROM PUBLIC.LONDON_WEATHER) UNION ALL
(SELECT 'PRECIPITATION' COL_1, 'VISIBILITY' COL_2, CORR(PRECIPITATION,VISIBILITY) CORR
FROM PUBLIC.LONDON_WEATHER) UNION ALL
(SELECT 'PRECIPITATION' COL_1, 'WINDSPEED' COL_2, CORR(PRECIPITATION,WINDSPEED) CORR
FROM PUBLIC.LONDON_WEATHER)
UNION ALL
(SELECT 'VISIBILITY' COL_1, 'WINDSPEED' COL_2, CORR(VISIBILITY,WINDSPEED) CORR
FROM PUBLIC.LONDON_WEATHER)
UNION ALL
(SELECT 'PRECIPITATION' COL_1, 'TEMP' COL_2, CORR(PRECIPITATION,TEMP) CORR
FROM PUBLIC.LONDON_WEATHER)
UNION ALL
(SELECT 'VISIBILITY' COL_1, 'PRECIPITATION' COL_2, CORR(VISIBILITY,PRECIPITATION) CORR
FROM PUBLIC.LONDON_WEATHER)
UNION ALL
(SELECT 'WINDSPEED' COL_1, 'TEMP' COL_2, CORR(WINDSPEED,TEMP) CORR
FROM PUBLIC.LONDON_WEATHER) UNION ALL
(SELECT 'VISIBILITY' COL_1, 'TEMP' COL_2, CORR(VISIBILITY,TEMP) CORR
FROM PUBLIC.LONDON_WEATHER)
UNION ALL
(SELECT 'WINDSPEED' COL_1, 'PRECIPITATION' COL_2, CORR(WINDSPEED,PRECIPITATION) CORR
FROM PUBLIC.LONDON_WEATHER) UNION ALL
(SELECT 'WINDSPEED' COL_1, 'VISIBILITY' COL_2, CORR(WINDSPEED,VISIBILITY) CORR
FROM PUBLIC.LONDON_WEATHER)
We can see the highest correlations are between temperature and visibility
Identifying outliers, or points that lie at the most extreme ends of your dataset, is a crucial to the rest of your analysis. Early identification, and potential removal of outliers makes for more accurate predictions and a better understanding of your data.
There are many ways to define outliers, but for this example, we'll use Tukey's fences:
We can use PERCENTILE_CONT to find our 25th and 75th percentiles:
SELECT PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY WINDSPEED) "Q1",
PERCENTILE_CONT(0.75) WITHIN GROUP (ORDER BY WINDSPEED) "Q3"
from PUBLIC.LONDON_WEATHER
This means we can define an outlier that is outside of the following upper and lower bounds:
SELECT (Q1-1.5*(Q3-Q1)) LOWER_BOUND , (Q3+1.5*(Q3-Q1)) UPPER_BOUND FROM IQR
Select WINDSPEED from PUBLIC.LONDON_WEATHER cross join IQR where WINDSPEED not between (Q1-1.5*(Q3-Q1)) AND (Q3+1.5*(Q3-Q1))
This page was built using Count, the first notebook built around SQL. It combines the best features of a SQL IDE, Data Visualization Tool, and Computational Notebooks. In the Count notebook, each cell acts like a CTE, meaning you can reference any other cell in your queries.
This makes not only for far more readable reports (like this one) but also a much faster and more powerful way to do your analysis, essentially turning your analysis into a connected graph of data frames rather than one-off convoluted queries and CSV files. And with a built-in visualization framework, you won't have to export your data to make your charts. Go from raw data to interactive report in one document.