Posts

Pandas - Python library.

Image
 Pandas Pandas is open source python library .  Used for data analysis . Also helpful in data mungling . Data Mungling -  Combination of data cleaning, data manipulation, and data understanding we call it as data munging. How to install pandas. Type pip install pandas in your cmd. If you are using anaconda (it is a python distribution) in this the pandas is already installed. To check the pandas version We import pandas as import pandas as pd. Type - pd.__version__ Basic pandas function you should know. pd.read_csv - To read csv file. pd.head() - to print top 5 line. pd.tail() - to print last 5 line. pd.describe() - to describe the dataset. pd.info() - to check the complete info about the dataset. pd.shape - It's a attribute, help to know shape of dataset pd.shape[0] - print  number of rows. pd.shape[1] - print number of columns. pd.columns - It will print all the columns name. pd.column_name - The column_name that you want will be selected. pd['column_name'] - Sa...

Numpy - Slicing

Image
 Slicing in Numpy Arrays. As we all know that the slicing is about to print subpart of something.  Like when our parents bring cake we get the slice of that not the whole cake, it's something similar to this. Now slicing in numpy array is like printing or getting the value from first index till last index. I am going to discuss slicing in advance. Numpy array with two dimensions. Basic information regarding slicing. Index is always start from 0. Negative indexing is also possible. We always try to figure our solution in [ row, column] format. If it's a single element the column number will be the exact one (see question 1 and 2). If it's more than one element then the previous rule will gonna apply like column - 1 (see question 3 and 4). We can access the particular element by giving rows and column index separated by comma. For accessing the group of elements you should pass the rows and columns by using the : symbol. Question - 1 print 10. Answer - As we all know that the...

Python - Functions

Image
 Functions Function in python it's same as the functions in any other programming language. Concept is same the syntax is differ. As we all know function is a block of code that perform some task. There are 3 types of function in python. In-built function - for e.g:- min(),  print(), add(). User defined function - That will be defined or created by the user. Anonymous function - is also known as lambda function because they are not declared with the def keyword. How to define a function in python use def  statement. followed by  function name . Add parameter to the function. All the parameter should enclosed with the parenthesis or  bracket and at the end of the function used 'colon' : When to use a function. Function should use when there is duplication of a task. It increase readability of the program. Return Statement  A return statement is used to return something from the function. It's only work for the function. If any other want to work wit...

Python - Dictionary

  Python Built-in Data Structure -- Dictionary 1.  Dictionary items are ordered, changeable, and does not   allow duplicates. 2.   Dictionary items are presented in key:value pairs, and   can be referred to by using the key name. 3.   Dictionary items are mutable. 4.   Dictionary are iterable. Dictionary Methods It has total of 11 methods.  Clear () – It’s used to remove all the items from the dictionary. Copy () – It’s used to return the copies of the given dictionary. Keys () - The keys () method returns a view object. The view object contains the keys of the dictionary, as a list. The view object will reflect any changes done to the dictionary. Values () - The values () method returns a view object. The view object contains the values of the dictionary, as a list. The view object will reflect any changes done to the dictionary. Items () – The items () method returns a view object. The view...

Python - Set

Image
 Built-in Data Structure -- Set Introduction to Set We all are studied Set in our class 10th. The same concept is applied here. All the set operations you will get in this. Stay with me. You will know the Set and able to teach anyone about it. So, very first question is What is Set? Let's answer this question later just recall what you know about Set. Think for minute or 5 ......... Tick, Tick, Tick. Have you recalled it. I guess so. If not leave on me. Kidding. Pay attention here guys.  Set is an unique collection of item. Set has no duplicate elements. It's an unordered data structure. Since sets are unordered, we cannot access items using indexes like we do in a list and tuple. Slicing is not possible. It is Iterable. It is Mutable. Creation of Set Set is created using { } curly bracket or set constructor . To create an empty set , use set function . As shown in image. Important Set functions. As, we all not basic set operations is like, Union, Intersection, Discard, Diff...

Python - Interview Questions basics.

Image
Interview Questions. Difference between  Iteration, Iterable and Iterator? Iteration - Repetition of a process. Iterable -  A python object which supports iteration e.g list, tuple, string, range, set. Iterator -  A python object which enable us to iterate over the iterable.  Difference between tuple and list? List is mutable. Tuple is immutable. List consume more memory and slow. Tuple consume less memory and fast. When you are returning something from the function the returned value is tuple.  Difference between map, filter and reduce with example? Map -  The map() function is a higher-order function. As previously stated, this function accepts another function and a sequence of ‘iterables’ as parameters and provides output after applying the function to each iterable in the sequence. It has the following syntax: SYNTAX:   map(function, iterables) map() function returns  a map object(which is an iterator) of the results after applying the g...

Python - Tuples

Image
 Introduction to Tuple. Just like list, tuple is also used to store sequence of element. Tuple elements can be of any data types. Tuple are immutable. Tuple are iterable. Tuple are ordered built-in data types and unchangeable.  Tuple is created using the round brackets i.e, () or tuple() constructor. Tuple allows duplicate elements. Tuple supports indexing. Tuple supports slicing. Concatenation and Replication is possible. Tuple are Unchangeable. It's means once we have created a tuple using round bracket or  tuple constructor. We can't change , add, or remove item of tuple. If we try to do that, it's gives error that Tuple object does not support item assignment. Tuple Methods. Built-In Function Len() - Returns the total number of elements in a tuple. Sum() - Returns the sum of all the elements in a tuple. Min() - Returns the minimum elements in a tuple. Max() - Returns the maximum elements in a tuple. Function used to count the number of time specif...