About Me

My photo
Mumbai, Maharastra, India
He has more than 7.6 years of experience in the software development. He has spent most of the times in web/desktop application development. He has sound knowledge in various database concepts. You can reach him at viki.keshari@gmail.com https://www.linkedin.com/in/vikrammahapatra/ https://twitter.com/VikramMahapatra http://www.facebook.com/viki.keshari

Search This Blog

Sunday, September 1, 2019

How immutable objects are treated in python function

ImMutable: An immutable object can’t not be changed after it is created, example are: any build-in datatype-int, float, str, bool, tuple)

What exactly it means that, when you declare and initialize any immutable variable, it preserve a space in the memory, and the moment you change the value of the variable, modified value get a new  space in memory.

>>> a=3
>>> a
3
>>> id(a)
1812388048
>>> a=a+2
>>> a
5
>>> id(a)
1812388080
>>> type(a)
<class 'int'>

Here in above example if you see, Variable “a” is initialized with value 3 and it occupies memory address of 1811288048, and the moment we tried to update the value of Variable ‘a’ to 5, the modified value i.e. 5 gets a  new memory space which is 1812388080, that is because of immutable characteristics of int datatype.

Now lets create a function, here the function takes a parameter of int type

def updateNumber(n):
   
print(id(n))
    n+=
10
   
print(n)

lets try to call the function with a int variable

def updateNumber(n):
   
print('Inside function, before modifying value of a, Mem address of n = ',id(n))
    n+=
10
   
print('Value of a inside function after modification =', n)

a=
5
print('Before calling function Mem address of a = ', id(a))
updateNumber(a)
print('Value of a after calling function = ', a)

Output:

Before calling function Mem address of a =  1812388080
Inside function, before modifying value of a, Mem address of n =  1812388080
Value of a inside function after modification = 15
Value of a after calling function =  5

Here if you see, the location of n inside the function is same as location of a, before calling function i.e. 1812388080, then function modify the value of n from 5 to 15 so inside function when we tried to print the value of n, it gave 15. But once we came out of function and tried to print the value of a, it still gave 5 unchanged.

That means modification of value inside function was not retained outside function. Lets find out why .. by printing a location of n after modifying the value of n in function.

def updateNumber(n):
   
print('Inside function, before modifying value of a, Mem address of a = ',id(n))
    n+=
10
   
print('Inside function after modification of value of n, location of n is = ', id(n))
   
print('Value of a inside function after modification =', n)

a=
5
print('Before calling function Mem address of a = ', id(a))
updateNumber(a)
print('Value of a after calling function = ', a)
print('After calling function Mem address of a = ', id(a))

Output:

Before calling function Mem address of a =  1812388080
Inside function, before modifying value of a, Mem address of a =  1812388080
Inside function after modification of value of n, location of n is =  1812388240
Value of a inside function after modification = 15
Value of a after calling function =  5
After calling function Mem address of a =  1812388080

Here we can see, the location of n inside function was same as a outside function but the moment function modifies the value of n, it took a separate location and that is the reason why a value even after modifying it inside function didn’t change.

The reason behind this kind of behavior is datatype int is immutable.


Data Science with…Python J
Post Reference: Vikram Aristocratic Elfin Share

Sunday, August 25, 2019

Creating first database in Azure SQL Database

Login to your Azure Account, here below you can see there is no resource… Click on SQL Database service on left vertical panel



Here you can see there is no SQL Database listed, click on Add on right top area



Few item which need to be understood before creating any database

Subscription: All resources in azure subscription are billed together. You need to select your subscription here.

Resource group: A container that holds related resources for an Azure solution. The resource group includes those resources that you want to manage as a group. You decide how to allocate resources to resource groups based on what makes the most sense for your organization.

Resource: A manageable item that is available through Azure. Virtual machines, storage accounts, web apps, databases, and virtual networks are examples of resources.

Elastic Pool: SQL Database Elastic Pool is a shared resource model that enables higher resource utilisation efficiency, with all the databases within an elastic pool sharing predefined resources within the same pool.

Any database in Azure need to be created under a logical server, to create a logical server, click create new under server link and enter the server name and login detail.



Now configure storage and DTU (database throughput unit), here I am keeping it default Basic



The final version of configuration



Now click on Resource Group and select the recently created resource to see all resource which we created just above .. i.e. server and database



Now we are ready with our first ever database in Azure, lets connect it with SSMS client, but before that, we need to set the firewall to allow our client SSMS IP address registered in Azure logical SQL Server

For setting the firewall in newly created logical SQL Server, go to resource group à go to sql database created à select set server firewall



Click Add Clien IP à Give the IP address à Press Save



Once that is done, go to the resource group à. Select the newly created resource à select the newly created server à go to the server properties à copy the server name



Now lets open SSMS at client machine, enter the server detail which was copied from above, put the login name and password which was set in above steps



Now we are able to connect to our first Azure database




Enjy coding…SQL Azure J
Post Reference: Vikram Aristocratic Elfin Share

Different Flavor of Azure SQL Database


We have three different Kind of Databaase deployment in Azure SQL database:
  •          Singleton:
  •          Elastic Pool:
  •          Managed Instance




Singleton : With a single database, each database is isolated from each other and portable, each with its own service tier within the DTU-based purchasing model. The single database deployment option creates a database in Azure SQL Database with its own set of resources and is managed via a SQL Database server.

Elastic Pool: SQL Database elastic pools are a simple, cost-effective solution for managing and scaling multiple databases that have varying and unpredictable usage demands. The databases in an elastic pool are on a single Azure SQL Database server and share a set number of resources at a set price.

Managed Instance: A managed instance in Azure SQL Database is a fully managed SQL Server Database Engine Instance hosted in Azure cloud. This is the best PaaS option for migrating your SQL Server database to the cloud.


Note: For Azure SQL Database single databases and elastic pools, only master Database and tempdb Database apply. For Azure SQL Database Managed Instance, all system databases apply. For more information on Managed Instances in Azure SQL Database

Post Reference: Vikram Aristocratic Elfin Share

Thursday, July 18, 2019

Tableau Filter 3: Establishing relationship between filter column


What we are trying to achieve is that, if we have two filter like Category and Sub-Category, on selecting category, the associated sub-category should get populated in the subcategory filter list..



Here if you see in above picture right vertical panel, I have selected Category as “Furniture” and under Furniture we have only four sub category but in filter we can see it list out all sub category.

So what exactly we want is when user selects furniture in filter only those subcategory which belongs to Furniture should get displayed in subcategory filter.



Go to Sub-Category Filter à Click on Only Relevant value, here in below figure you can see only Sub-Category are now refined to show only those sub category which belongs to Furniture.



Same way on selecting Category as Office Supplies, Sub-Category filter shows only those items which belongs to Office Supplies.





Enjy Tableau J
Post Reference: Vikram Aristocratic Elfin Share

Wednesday, July 17, 2019

Tableau: Applying Filter and Color combination to your dataset-II

Prev Post:


Lets talk about Interactive filter, here you can select at runtime which subset of data you want to see, let’s take an example from the Superstore dataset, where we want to see all order made in a particular year same want we also want to get subset of selected sub category


From the above set, I am interested in selecting subset of data say 2014, 2015 and category I am interested is Furniture and office supplies

So what you need to do is to
Go to the column “Year”à RClick go to Show Filter à Filter selection will come in right panel with value to select at runtime, same way you need to
Go to category à Rclick go to Show Filter à Filter selection will come in right panel with value to select at runtime


So now here from right side filter panel, you can select year as well as category you want to see the data, lets select 2014 and 2015 as year and category as Furniture


In next post we will see how to establish relationship with two or more filter column..


Enjy Tableau J
Post Reference: Vikram Aristocratic Elfin Share

Monday, July 15, 2019

Tableau: Applying Filter and Color combination to your dataset-I


Tableau provide different kind of filter
1)       Filter Shelf
2)       Interactive filter

Filter Shelf: Continuing with the Superstore dataset, if we want to filter number of sales on the basis of OrderDate, then just drag orderDate from Dimension to Filter panel, the moment you drag the column to filter panel, a dialog box will appear like below which ask for which year you want to extract the number of sales, in this example we have taken 2016 and 2017 years in filter to see the sales made. Just select the years you want to see and click ok.



After applying filter, we have filtered sales number just for 2016 and 2017 year


Now if you want to see all only these category where sales number are greater than 50,000, in that case drag the sales from Measure and put it to Filter Panel, once you drop the sales measure to filter panel, a dialog box will appear where you can select
·          At Least
·          At Most
·          Range
·          Special; which is used to filter NULL values

In our case lets select At Most tab and keep the value as 50,000, because we are interested to see all category where sales made are more than 50,000



Once you apply above filter your data is filter to show only those category where sales made are greater than 50,000.


Enjy Tableau J
Post Reference: Vikram Aristocratic Elfin Share

Sunday, July 14, 2019

Tableau: Creating Hierarchies and drill down

Tableau provide functionality to drill down from highest level to lowest level of granularity, with the help of + and – symbol in the report column.

I am taking superstore dataset for this example which is free dataset to be used for analysis.

Creating Hierarchies

Here below if we see, I have taken Segment|Category|Sub-Category as a row granularity over which I am trying to find number of sales made under each granularity.

 



What if, I want see how many sales made each year under consumer segment and then drill down to see consumer-furniture thereafter consumer-furniture-chairs..

To fulfill this kind of requirement, Tableau reporting has provided column hierarchy. Let’s see how to form hierarchy
Go to Column à RClick à Create Hierarchy

  

Once the hierarchy is created go to column which you want to add to the hierarchy à RClick à Hierarchy à add to existing hierarchy. In below example you can see Hierarchy is created with name “Segment-Cat-SubCat” and three columns are added to the hierarchy i.e. segment, category and sub category.



Also in above figure you can see in Rows, the segment comes with + prefix, which means if has further drill down.
In below figure if you click on +Segment à it will break into Segment and +Category

 


Same way if you click on +Category à it will break into Category and Sub-Category as show in below figure



Enjy Tableau J
Post Reference: Vikram Aristocratic Elfin Share