credit: pixabay.com

My Data Science Week 4

Soumyabrata Roy
4 min readJan 1, 2019

--

This week I feel that I should start with the wonderful medium post about the basics of Statistics The 5 Basic Statistics Concepts Data Scientists Need to Know. It is really a good article by George Seif. It will help you to realize you don’t need to know whole lot of concepts, theories to start with the Data Science. Simple stat concepts can be applied to your day to day Data Science journey.

Now let’s talk about the simple SQL commands for Data Analysis. For the below examples, I have used the Posgre SQL engine with PG Admin interface. Hope you will find it useful. For the demonstration I have used the DVD rental data base film table.

And here is the different simple commands and corresponding outputs for the same.

SELECT * FROM film LIMIT 5;

It gives the first 5 rows from the table.

SELECT COUNT(*) FROM film;

It counts the total number of rows in the table. This simple command will save your time from browsing till the end of the table to find out the number of rows.

SELECT * FROM film WHERE title LIKE ‘Cham%’;

This command will help you to find the filtered data from the table. Here I have filtered the data in the sense to find out the number of films which starts with the name Cham. As you can see I have got two results out of 1000 films whose name starts with Cham.

SELECT * FROM film WHERE rental_rate IN (4.99, 0.99);

This particular command will help you to filter out the data with multiple conditions. Here the rental_rate is equal to either 4.99 or 0.99. You could also write the same command in this way SELECT * FROM film WHERE rental_rate = 4.99 or rental_rate = .99; both are same but maybe the first one is more compact.

Now let’s go to Python. Today we will talk about the Python LEGB rule.

So what is LEGB rule in Python? LEGB stands for L: Local, E: Enclosed local, G: Global, B: Built-in. Python always works in this manner L => E => G => B.

for example see the below function

there are three values of x. 100, 50, 10.

x = 100 is Global value, x = 50 is a enclosed local value and x = 10 is the local value as it is defined inside of the enclosed function func1() of the previous function function()

if I call only x I get the global value of x as shown in the figure.

Now if I call the function(), I get the local value as you can see. and If I commented out the local value, I will get the enclosed local value and again if I commented out the enclosed local one, I will get the global value of x. So the value of x moved by LEGB rule.

And the Built in functions are always reserved like len(), max(), min() etc. They are the upper most by the LEGB rule in Python.

Hope you have got some valuable information. I will get back again next week.

Originally published at https://www.linkedin.com on January1, 2019.

--

--

Soumyabrata Roy

Data Scientist Cognizant | Answering what, why, and how of different business scenarios through machine learning and deep learning.