Posts

Explain How to create a series from a list, numpy array and dict?

 Explain How to create a series from a list, numpy array and dict? import pandas as pd import numpy as np list = ["k","h","o","s","e"] Dict = {"k": 1,"h" : 2,"o" : 3,"s" :5,"e" :4} np = np.array(["k","h","o","s","e"]) print(pd.Series(list)) print("\n") print(pd.Series(Dict)) print("\n") print(pd.Series(np))

Explain different ways to create an empty NumPy array in Python.

There are two ways an empty NumPy array can be created: numpy.zeros and numpy.empty . import numpy as np print(np.empty((4,4))) print("\n") print(np.zeros((4,4)))

How will you find, in a string, the first word that rhymes with 'cake'?

Python has a built-in package called re , which can be used to work with Regular Expressions. Import the re module: import re. RegEx in Python. For our purpose, we will use the function search() , and then use group() to get the import re rhyme = re.search(".ake","I would like to make a cake") print(rhyme.group())  Out : 'make' And as we know, the function search() stops at the first match. Hence, we have our first rhyme to 'cake'.

What is the process to calculate percentiles with NumPy?

import numpy as np #np.percentile(arr,n,axis= (1,0)) # n = percentile, 1= row, 0 = column arr = [10,20,30,40,50,60] print(np.percentile(arr,5)) # 2D  arr1 = [[10,20,30,40],[50,60,70,80]] print(np.percentile(arr1,5))

Python simple project using Numpy

Image
Numpy :  1. Creating numpy  2. Finding dimension, data type, shape,  reshape  3. Creating numpy with different way 4. Applying mathematics  5. Compared two array  6. Aggregate function  7. Array manipulations -- concatenate two array, stack array vstack and hstack, split two array 8. Sorting array import numpy as np  a = np.array([1,2,3,4]) b = np. array([5,6,7,8]) print(a.size) print("\n") print(a.ndim) print("\n") print(a.dtype) print("\n") print(a.shape) print("\n") print(np.linspace(1,10,2)) print("\n") print(np.arange(1,10,2)) print("\n") x = np.logspace(1,10,2) print(x) print("\n") print(np.zeros((4,2))) print("\n") print(np.ones((4,2))) print("\n") print(np.full((4,2),4)) print("\n") print(np.random.rand(2,4)) print("\n") print(np.sum([a,b],axis=0)) print("\n") print(np.subtract(a,b)) print("\n") print(np.multiply(a,b)) print(np.divide(a,b)) print(...

Pie Chart , Donut Plot, Area plot

Image
Pie Chart : import matplotlib.pyplot as plt a= ["apple","banana","mango"] b = [30,10,80] fig = plt.figure(figsize=(10,5)) plt.pie( b,labels=a, autopct = "%1.1f%%", shadow=True, startangle = 90 ) plt. show() Customizing Pie Chart : import matplotlib.pyplot as plt a= ["apple","banana","mango"] b = [30,10,80] fig = plt.figure(figsize=(10,5)) plt.pie(b,labels=a,autopct = "%1.1f%%" , shadow=True, startangle = 90, explode= (0.1,0.1,0) ) plt. show() Pie Chart Without Shadow : import matplotlib.pyplot as plt a= ["apple","banana","mango"] b = [30,10,80] fig = plt.figure(figsize=(10,5)) plt.pie(b,labels=a,autopct = "%1.1f%%", shadow= False , startangle = 90,     explode= (0.1,0.1,0)) plt. show() Donut Plot : import matplotlib.pyplot as plt name= ["kanchan" ,"kariahma","kajal",] marks = [80,85,90] center=[10] fig ...

Violin Plot

Image
Violin Plot : import matplotlib.pyplot as plt a = [1,2,35,9,10,15] b = [5,20,12,25,7,38] c= [3,7,18,22,14,31] data = list([a, b, c]) plt.violinplot(data, showmeans=True, showmedians = True ) plt.show() Customizing Violin Plot : import matplotlib.pyplot as plt a = [1,2,35,9,10,15] b = [5,20,12,25,7,38] c= [3,7,18,22,14,31] data = list([a, b, c]) fig = plt.figure(figsize=(10,5)) plt.violinplot(data,showmeans=True, showmedians = True) plt.legend() plt.grid(True) plt.xlabel("x") plt.ylabel("y") plt.show() Adding Two Violin Plot :  import matplotlib.pyplot as plt a = [1,2,35,9,10,15] b = [5,20,12,25,7,38] c= [3,7,18,22,14,31] a1 = [1,2,35,9,10,15] b1= [5,20,12,25,7,38] c1= [3,7,18,22,14,31] data = list([a, b, c]) data1 = list([a1, b1, c1]) fig = plt.figure(figsize=(10,5)) plt.subplot(1,2,1) plt.violinplot(data,showmeans=True, showmedians = True ) plt.legend() plt.grid(True) plt.xlabel("x") plt.ylabel("y...