Wednesday, 13 May 2020

What is Matplotlib in Data Visualization? | Python crash course_03

What is Matplotlib in Data Visualization?

Hello everyone, welcome to Python crash course. Today I am going to Explain What is Matplotlib in Data Visualization? Let's Start:

Introduction about Matplotlib:
A pictures is worth a thousand word, and with Python’s matplotlib library, it, fortunately, take far less than a thousand words of code to create a production-quality graphic.However, matplotlibs is also a massive library, and getting a plot to looks just right is often achieved through trial and error. Using one-liners to generate basic plot in matplotlib is fairly simple, but skillfully commanding the remaining 97% of the library can be daunting.
This articles is a beginner-to-intermediate-level walkthrough on matplotlib that mixe theory with example. While learning by example can be tremendously insightful, it helps to have even just a surface-level understanding of the library’s inner working and layout as well.
SOME EXAMPLE OF MATPLOTLIB:
In this chapter, we will learn how to create a simple plots with Matplotlib.
We shall now display a simple line plots of angle in radians. its sine values in Matplotlib. To begin with, the Pyplot module from Matplotlib package is imported, with an alias plot as a matter of convention.
import matplotlib.pyplot as plt
Next we need an array of number to plot. Various array function are defined in the Numpy library which is imported with the np alias.
import numpy as np
We now obtain the ndarray object of angle between 0 and 2π using the arange() function from the Numpy library.
x = np.arange(0, math.pi*2, 0.05)
The ndarray object serves as values on x axis of the graphs. The corresponding sine values of angles in x to be displayed on y axis are obtained by the following statements −
y = np.sin(x)
The value from two arrays are plotted using the plot() functions.
plt.plot(x,y)
You can set the plots title, and labels for x and y axes.
#You can set the plots title, and labels for x and y axes.
plt.xlabel("angle")
plt.ylabel("sine")
plt.title('sine wave')


The Plots viewer window is invoked by the show() function −
plt.show()
The complete programs is as follow −
from matplotlib import pyplot as plt
import numpy as np
import math #needed for definition of pi
x = np.arange(0, math.pi*2, 0.05)
y = np.sin(x)
plt.plot(x,y)
plt.xlabel("angle")
plt.ylabel("sine")
plt.title('sine wave')
plt.show()
Simple Plot

FOR DETAILED PLEASE OPEN BELOW LINK:
                                           BEST OF LUCK!!!!!!


Tuesday, 12 May 2020

Reshape the Matrix | Python

Problem Statement:

In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data.

You're given a matrix represented by a two-dimensional array, and two positive integers r and c representing the row number and column number of the wanted reshaped matrix, respectively.

The reshaped matrix need to be filled with all the elements of the original matrix in the same row-traversing order as they were.

If the 'reshape' operation with given parameters is possible and legal, output the new reshaped matrix; Otherwise, output the original matrix.

Example 1:
Input:
nums =
[[1,2],
 [3,4]]
r = 1, c = 4
Output:
[[1,2,3,4]]
Explanation:
The row-traversing of nums is [1,2,3,4]. The new reshaped matrix is a 1 * 4 matrix, fill it row by row by using the previous list.
Example 2:
Input:
nums =
[[1,2],
 [3,4]]
r = 2, c = 4
Output:
[[1,2],
 [3,4]]
Explanation:
There is no way to reshape a 2 * 2 matrix to a 2 * 4 matrix. So output the original matrix.
Note:
The height and width of the given matrix is in range [1, 100].
The given r and c are all positive.


Code:

class Solution:
    def matrixReshape(self, nums: List[List[int]], r: int, c: int) -> List[List[int]]:
        k=len(nums);
        m=len(nums[0]);
        if(k*m==r*c):
            l=[];
            for i in nums:
                l=l+i;
            i=0;
            j=0;
            output=[];
            k=[];
            temp=0;
            while(i<r):
                while(j<c):
                    k.append(l[temp]);
                    temp+=1;
                    j=j+1;
                output.append(k);
                k=[];
                j=0;
                i=i+1;
            return output;
        else:
            return nums;

All About Pandas in Data Science | python crash course_02

All About Pandas in Data Science:

Hello friend, Today I am going to explain What is pandas in Data Science? so Let start:
This tutorial has been prepared for those who seek to learn the basic and various functions of Pandas. It will specifically useful for people working with data cleansing and analysis. After completing this tutorial, you will find yourself at moderate level of expertise from where you can take yourself to higher level of expertise.
Pandas is an open-source, BSD-licen Python library providing high-performance, easy-to-use data structures and data analysis tool for the Python programming language. Python with Pandas is used in wide range of field including academic and commercial domain including finance, economic, Statistic, analytics, etc. In this tutorial, we will learn the various feature of Python Pandas and how to use them in a practice.
Pandas deals with the following three data structure 
Series
DataFrame
Panel
These data structure are built on top of Numpy array, which mean they are fast.
Standard Python distribution doesn not come bundled with Pandas module. A lightweight alternative is install Numpy using popular Python package installer, pip.
pip install pandas 
import pandas as pd

SOME EXAMPLE OF PANDAS LIBRARY:
There are two kind of sorting available in Pandas. They are 
  • 1.By label
  • 2.By Actual Value
import pandas as pd
import numpy as np

unsorted_df=pd.DataFrame(np.random.randn(10,2),index=[1,4,6,2,3,5,9,8,0,7],colu
mns=['col2','col1'])
print unsorted_df

OUTPUT:

        col2       col1
1  -2.063177   0.537527
4   0.142932  -0.684884
6   0.012667  -0.389340
2  -0.548797   1.848743
3  -1.044160   0.837381
5   0.385605   1.300185
9   1.031425  -1.002967
8  -0.407374  -0.435142
0   2.237453  -1.067139
7  -1.445831  -1.701035

From 3D ndarray (FOR PANEL CREATION)


import pandas as pd
import numpy as np

data = np.random.rand(2,4,5)
p = pd.Panel(data)
print p
output:

<class 'pandas.core.panel.Panel'>
Dimensions: 2 (item) x 4 (major_axis) x 5 (minor_axis)
Items axis: 0 to 1
Major_axis axis: 0 to 3
Minor_axis axis: 0 to 4



FOR DETAIL PLEASE DRIVE LINK:
https://drive.google.com/open?id=1RKv0v0V9kfvMceWb2QHdWfavDffsGAgV
FOR MORE DETAILED ABOUT PANDAS PLEASE OPEN BELOW LINK:



Sunday, 10 May 2020

What is Numpy library in python? | python crash course_01

What is the Numpy library in python?
 Hello everyone, welcome to my python crash course. In the previous blog post, I released the python syllabus so it's time to start the tutorial. Let's start:

Numpy

What is a Python NumPy?

Numpy is Python package that stands for ‘Numerical Python’. It is the core library for scientific computing, which contain a powerful n-dimensional array object, provide tool for integrating C, C++, etc. It is also useful in linear algebra, random number capability. Numpy array can also used as an efficient multi-dimensional container for generic data. Now, let me tell you what exactly is python Numpy array.
NumPy ArrayNumpy array is powerful N-dimensional array object which is in the form of row and column. We can initialize numpy arrays from nested Python lists and access it element. In order to perform these numpy operation, the next question which will come in your mind is:


How do I install NumPy?

To install Python Numpy, go to your command prompt and type “pip install Numpy”. Once the installation is completed, go to your IDE and simply import it by typing: “Import Numpy as np”
Moving ahead in python numpy tutorials, let us understand what exactly is a multi-dimensional Numpy array.

Trigonometric Function

Numpy has standard trigonometric function which return trigonometric ratios for a given angle in radian.
Example

import numpy as np 
a = np.array([0,30,45,60,90]) 

print 'Sine of different angles:' 
# Convert to radian by multiplying with pi/180 
print np.sin(a*np.pi/180) 
print '\n'  

print 'Cosine values for angles in array:' 
print np.cos(a*np.pi/180) 
print '\n'  

print 'Tangent values for given angles:' 
print np.tan(a*np.pi/180) 
output is:
Sine of different angles:
[ 0.          0.5         0.70710678  0.8660254   1.        ]

Cosine values for angle in array:
[  1.00000000e+00   8.66025404e-01   7.07106781e-01   5.00000000e-01
   6.12323400e-17]                                                            

Tangent values for given angle:
[  0.00000000e+00   5.77350269e-01   1.00000000e+00   1.73205081e+00
   1.63312394e+16]
for detail information please open below  drive link:
https://drive.google.com/open?id=1tiE_cc8O8yRBYNKrSnhd8TO2mdZKdHtW
FOR DETAILED PLEASE CLICK BELOW:
CLICK HERE 
(NOTE: If any question then comment)
                                                          BEST OF LUCK!!!!!


Print first n numbers made up of some particular digits | Queue Application | Python

Prerequisite: Stacks and Queues using List | Data Structures | Python | Castor Classes https://www.youtube.com/watch?v=bMVBW... Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Code:
x=int(input('Enter the first digit:'));
y=int(input('Enter the second digit:'));
l=[];
q=[];
n=int(input("How many numbers you want?"));
i=0;
q.append(str(x));
q.append(str(y));
while(i<n):
    es=q.pop(0);
    l.append(int(es));
    ex=es+str(x);
    q.append(ex);
    ey=es+str(y);
    q.append(ey);
    i=i+1;
print(l)

Friday, 8 May 2020

IN operator as a shorthand for multiple OR conditions in Python

what is python? | overview about python language

Hello everyone, welcome to my blog post, today we have to start python crash course so first upon required to know the basics of this programming language hence let's start.
INTRODUCTION TO PYTHON:
(Befor the starting the section please read the this post: CLICK HERE)
Python was conceived in the late 1980s as a successor to the ABC language. Python 2.0, released in 2000, introduced features like list comprenstion and a garbage collection system capable of collecting reference cycle. Python 3.0, released in 2008, was a major revision of the language that is not completely backward, and much Python 2 code does not run unmodified on Python 3.
The Python 2 language was officially discontinued in 2020 (first planned for 2015), and "Python 2.7.18 is the last Python 2.7 release and therefore the last Python 2 release. No more security patches or other improvements will be released for it. With Python 2's end of life, only Python 3.5.x and later are supported.
Python is a general purpose and high level programming language. You can use Python for developing desktop GUI applications, websites and web applications. Also, Python, as a high level programming language, allows you to focus on core functionality of the application by taking care of common programming tasks.
Python is an object-oriented programming language created by Guido Rossum in 1989. It is ideally designed for rapid prototyping of complex applications. Python programming is widely used in Artificial Intelligence, Natural Language Generation, Neural Networks and other advanced fields of Computer Science.
(Note: If you want to read more introduction then click on Read more)
                                            BEST OF LUCK!!!!

Evaluate Reverse Polish Notation | Python

Problem Statement:
Evaluate the value of an arithmetic expression in Reverse Polish Notation.

Valid operators are +, -, *, /. Each operand may be an integer or another expression.

Note:

The division between two integers should truncate toward zero.
The given RPN expression is always valid. That means the expression would always evaluate to a result and there won't be any divide by zero operation.
Example 1:

Input: ["2", "1", "+", "3", "*"]
Output: 9
Explanation: ((2 + 1) * 3) = 9
Example 2:

Input: ["4", "13", "5", "/", "+"]
Output: 6
Explanation: (4 + (13 / 5)) = 6
Example 3:

Input: ["10", "6", "9", "3", "+", "-11", "*", "/", "*", "17", "+", "5", "+"]
Output: 22
Explanation:
  ((10 * (6 / ((9 + 3) * -11))) + 17) + 5
= ((10 * (6 / (12 * -11))) + 17) + 5
= ((10 * (6 / -132)) + 17) + 5
= ((10 * 0) + 17) + 5
= (0 + 17) + 5
= 17 + 5
= 22




Code:
class Solution:
    def evalRPN(self, tokens: List[str]) -> int:
        l=[];
        for i in tokens:
            if(i=='+' or i=='-' or i=='*' or i=='/'):
                a=l.pop(-1);
                b=l.pop(-1);
                g=b+i+a;
                w=eval(g);
                e=int(w);
                l.append(str(e));
            else:
                l.append(i);
        return int(l[0]);

Thursday, 7 May 2020

if – if else – if else if ladder in C#

C#  IF Statement :

Syntax :

if(condition)
{
//code to be executed
}

Prog : Write a program to test whether a number is even or not





C#  IF-ELSE Statement :

Syntax :

if(Condition)
{
// code to be executed
}else
{
//Code if condition is false
}

Prog : Write a program to test whether a number is even or not




C# IF - ELSE - IF LADDER Statement :

Syntax :

if(Condition1)
{
//code to be executed
}else if (Condition2)
{
//code to be executed
}
else 
{
//Code when all the condition are false
}


Program : Write a program to print Grade of Student as per Marks.



Mathematical functions | Python

For more detail on math module , check the below link: https://docs.python.org/3/library/mat... Relationship between number of digits of a number and it's logarithm: https://math.stackexchange.com/questi... Python for beginners: https://www.youtube.com/watch?v=egq7Z...


Plus One | Python


Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Code:


class Solution:
    def plusOne(self, digits: List[int]) -> List[int]:
        g="";
        for i in digits:
            g+=str(i);
        e=int(g);
        e=e+1;
        g=str(e);
        w=list(g);
        output=[];
        for i in w:
            output.append(int(i));
        return output;


Majority Element | Python

Check the problem statement here:
https://leetcode.com/problems/majorit... Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Code:


class Solution:
    def majorityElement(self, nums: List[int]) -> int:
        nums.sort();
        return nums[len(nums)//2];


Max Consecutive Ones | Python

Check the problem statement here: Max Consecutive Ones https://leetcode.com/problems/max-con... Python for beginners: https://www.youtube.com/watch?v=egq7Z...
Code: class Solution: def findMaxConsecutiveOnes(self, nums: List[int]) -> int: g=""; for i in nums: g=g+str(i); e=g.split('0'); max=0; for i in e: if(max<len(i)): max=len(i); return max;

eval | Python

Explore more about eval here: https://docs.python.org/3/library/fun... https://towardsdatascience.com/python... To convert the string into a numerical value use the function eval(string ) Test the following : a=eval(input()); type(a) Give a as 16 & check whether eval is converting input to a proper numeric datatype or not. Give a as 16.32 & check whether eval is converting a to proper numeric datatype or not. Python for beginners: https://www.youtube.com/watch?v=egq7Z...

The continue Statement | Python

end parameter in print() | Python

Handling Exceptions | Python

You can catch an exception by implementing the try—except construct. This construct is broken into 2 major parts: • try block. The try block indicates the code which is to be monitored for the exceptions listed in the except expressions. • except clause. You can use an optional except clause to indicate what to do when certain classes of exception/error occur (e.g. resolve the problem or generate a warning message). There can be any number of except clauses in sequence checking for different types of error/exceptions. For more detail explanation , check this below link: https://docs.python.org/3/tutorial/er... Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Popular Posts

Categories

100 Python Programs for Beginner (49) AI (34) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (173) C (77) C# (12) C++ (82) Course (67) Coursera (226) Cybersecurity (24) data management (11) Data Science (128) Data Strucures (8) Deep Learning (20) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (34) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (59) Meta (22) MICHIGAN (5) microsoft (4) Nvidia (3) Pandas (4) PHP (20) Projects (29) Python (929) Python Coding Challenge (354) Python Quiz (22) Python Tips (2) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (3) Software (17) SQL (42) UX Research (1) web application (8) Web development (2) web scraping (2)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses