Professional Documents
Culture Documents
AP19110010030 Assignmnet-1 Lab
AP19110010030 Assignmnet-1 Lab
Kilaru Sravan
AP19110010030
CSE-A
NumPy
NumPy stands for Numerical Python and it is the fundamental package for scientific computing in Python.
In [1]:
import numpy as np
#we are importing numpy as np
#Creation of 1D array
num1=np.array([1,12,18,111])
print('1D Array:',num1)
#Creation of 2D array
num2=np.array([[1,22,23,45],[31,14,995,91],[1,4,5,33]])
print('2D Array:',num2)
1D Array: [ 1 12 18 111]
2D Array: [[ 1 22 23 45]
[ 31 14 995 91]
[ 1 4 5 33]]
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 1/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
In [7]:
print('shape of 1d',num1.shape)
print('shape of 2d',num2.shape)
shape of 1d (4,)
shape of 2d (3, 4)
In [8]:
[ 1 12 18 111]
[ 31 14 995 91]
Data Type(DTYPE)
In [10]:
In [11]:
Reshape
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 2/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
In [13]:
[5 6 7 8]]
Zeros
In [14]:
#It gives us the number of zero's we required based on size and shape given
arr = np.zeros(6)
print('single array',arr)
Random
In [16]:
Range
In [17]:
[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19]
[ 1 4 7 10 13 16 19]
Indexing
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 3/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
In [19]:
my array : [1 2 3 4 5]
1st posistion 1
2nd posistion 2
Sorting
In [20]:
Slicing
In [57]:
[1 2]
[3 4 5]
[5 4 3 2 1]
PANDAS
Pandas is a built in library using for data analysis.
Pandas is a open source data analysis library written in python
It provides rich and highly robust data operations
We will be using Pandas heavily for data manipulation, visualisation, building machine learning models, etc.
Pandas implements a number of powerful data operations familiar to users of both database frameworks
and spreadsheet programs.
There are two main data structures in Pandas - Series and Dataframes.
The default way to store data is dataframes, and thus manipulating dataframes quickly is probably the most
important skill set for data analysis.
A series is similar to a 1-D numpy array, and contains values of the same type (numeric, character,
datetime etc.).
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 4/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
In [21]:
#importing pandas as pd
import pandas as pd
Series
In [22]:
0 1
1 2
2 3
3 4
4 5
dtype: int64
<class 'pandas.core.series.Series'>
Dataframes
In [24]:
df=pd.DataFrame({
'name':['sravan','kilaru','teju'],
'marks':[60,10,100]
})
#creation of pandas data frame
df
#printing the data frame
Out[24]:
name marks
0 sravan 60
1 kilaru 10
2 teju 100
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 5/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
In [25]:
Maida flour,
Balu West
0 yogurt, oil, vegetarian 45 25 sweet dessert
shahi Bengal
sugar
Gram flour,
1 Boondi vegetarian 80 30 sweet dessert Rajasthan
ghee, sugar
Carrots,
Gajar milk, sugar,
2 ka ghee, vegetarian 15 60 sweet dessert Punjab
halwa cashews,
raisins
Flour, ghee,
kewra, milk,
3 Ghevar vegetarian 15 30 sweet dessert Rajasthan
clarified
butter, su...
Milk
powder,
Gulab plain flour, West
4 vegetarian 15 40 sweet dessert
jamun baking Bengal
powder,
ghee,...
Glutinous
rice, black
250 Til Pitha vegetarian 5 30 sweet dessert Assam
sesame
seeds, gur
Coconut
milk, egg
251 Bebinca yolks, vegetarian 20 60 sweet dessert Goa
clarified
butter, all...
Cottage
cheese, dry
Jammu &
252 Shufta dates, dried vegetarian -1 -1 sweet dessert
Kashmir
rose petals,
...
Milk
powder, dry
Mawa fruits, Madhya
253 vegetarian 20 45 sweet dessert C
Bati arrowroot Pradesh
powder,
all...
Brown rice,
fennel
seeds,
254 Pinaca vegetarian -1 -1 sweet dessert Goa
grated
coconut,
blac...
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 6/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
Maida flour,
Balu West
0 yogurt, oil, vegetarian 45 25 sweet dessert Ea
shahi Bengal
sugar
Gram flour,
1 Boondi vegetarian 80 30 sweet dessert Rajasthan We
ghee, sugar
Carrots,
Gajar milk, sugar,
2 ka ghee, vegetarian 15 60 sweet dessert Punjab Nor
halwa cashews,
raisins
Flour, ghee,
kewra, milk,
3 Ghevar vegetarian 15 30 sweet dessert Rajasthan We
clarified
butter, su...
Milk
powder,
Gulab plain flour, West
4 vegetarian 15 40 sweet dessert Ea
jamun baking Bengal
powder,
ghee,...
Sugar
West
5 Imarti syrup, lentil vegetarian 10 50 sweet dessert Ea
Bengal
flour
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 7/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
In [28]:
Green
beans,
main West
249 Shukto bitter gourd, vegetarian 10 20 spicy E
course Bengal
ridge gourd,
banana...
Glutinous
rice, black N
250 Til Pitha vegetarian 5 30 sweet dessert Assam
sesame E
seeds, gur
Coconut
milk, egg
251 Bebinca yolks, vegetarian 20 60 sweet dessert Goa W
clarified
butter, all...
Cottage
cheese, dry Jammu
252 Shufta dates, dried vegetarian -1 -1 sweet dessert & N
rose petals, Kashmir
...
Milk
powder, dry
Mawa fruits, Madhya
253 vegetarian 20 45 sweet dessert Ce
Bati arrowroot Pradesh
powder,
all...
Brown rice,
fennel
seeds,
254 Pinaca vegetarian -1 -1 sweet dessert Goa W
grated
coconut,
blac...
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 8/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
In [29]:
Aloo,
tomatoes,
Konir non main
240 mustard oil, -1 -1 spicy Assam
Dom vegetarian course
bay leaf,
cinnamo...
Curd,
cooked rice,
main
244 Pakhala curry vegetarian -1 -1 -1 Odisha
course
leaves, dry
chilli
Whole
wheat flour,
206 Sukhdi vegetarian 10 20 sweet dessert Maharashtra
gur, clarified
butter
Pav bhaji
masala,
Pav gobi, main
200 vegetarian 20 40 spicy Maharashtra
Bhaji potatoes, course
green peas,
...
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 9/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
In [30]:
df.describe()
Out[30]:
prep_time cook_time
df.dtypes
Out[31]:
name object
ingredients object
diet object
prep_time int64
cook_time int64
flavor_profile object
course object
state object
region object
dtype: object
print(df.columns) #it will show all the columns in the data set
dtype='object')
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 10/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
In [33]:
print(df.index)
df['state']
Out[34]:
0 West Bengal
1 Rajasthan
2 Punjab
3 Rajasthan
4 West Bengal
...
250 Assam
251 Goa
254 Goa
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 11/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
In [35]:
df.sort_values(['state'],ascending=False)
#if ascending=false it will sort index of rows from largest to smallest
Out[35]:
Maida flour,
West
0 Balu shahi yogurt, oil, vegetarian 45 25 sweet dessert
Bengal
sugar
Maida,
main West
224 Luchi vegetable vegetarian 20 30 -1
course Bengal
oil
Chicken,
dahi,
sesame
Chicken non main West
79 seeds, 10 35 spicy
razala vegetarian course Bengal
garam
masala
powd...
Moong dal,
garam
masala main West
84 Daal puri vegetarian 30 30 spicy
powder, course Bengal
garlic,
green ...
Rice flour,
jaggery,
West
36 Adhirasam ghee, vegetarian 10 50 sweet dessert
Bengal
vegetable
oil, elachi
Kala chana,
mashed
109 Pani puri potato, vegetarian 15 2 spicy snack -1
boondi, sev,
lemon
Urad dal,
ginger,
curry
162 Vada vegetarian 15 20 spicy snack -1 S
leaves,
green
chilies,...
Brown rice,
Brown main
231 soy sauce, vegetarian 15 25 -1 -1
Rice course
olive oil
Refined
flour,
besan,
12 Nankhatai vegetarian 20 30 sweet dessert -1
ghee,
powdered
sugar, yo...
Pigeon
peas,
eggplant, main
156 Sambar vegetarian 20 45 spicy -1 S
drumsticks, course
sambar
powd...
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 12/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 13/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
In [36]:
df.sort_values(['name'],ascending=True)
#ascending=True sort values from smallest to largest
Out[36]:
Rice flour,
jaggery,
36 Adhirasam ghee, vegetarian 10 50 sweet dessert West Be
vegetable
oil, elachi
Cauliflower,
potato,
garam main
68 Aloo gobi vegetarian 10 20 spicy Pu
masala, course
turmeric,
c...
Potato,
peas,
Aloo chillies, main
70 vegetarian 5 40 spicy Pu
matar ginger, course
garam
masala, ...
Potato,
fenugreek
main
71 Aloo methi leaves, vegetarian 10 40 bitter Pu
course
chillies, salt,
oil
Potato,
shimla
Aloo mirch,
main
72 shimla garam vegetarian 10 40 spicy Pu
course
mirch masala,
amchur
pow...
Urad dal,
ginger,
curry
162 Vada vegetarian 15 20 spicy snack
leaves,
green
chilies,...
Gobi,
potato,
Veg main
210 beans, khus vegetarian 20 30 spicy Maharas
Kolhapuri course
khus,
coconut
Baby corn,
french
Vegetable beans, main
121 vegetarian 10 30 spicy Pu
jalfrezi garam course
masala,
ginger,...
Chicken,
coconut oil,
non main
211 Vindaloo wine 10 40 spicy
vegetarian course
vinegar,
ginger, gr...
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 14/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
Gram flour,
mustard,
main
166 Zunka garlic, vegetarian 10 25 spicy Maharas
course
turmeric,
red chilli
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 15/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
In [37]:
df.sort_index(axis=1,ascending=False)
Out[37]:
Maida flour,
West Balu
0 East 45 yogurt, oil, sweet vegetarian dessert
Bengal shahi
sugar
Gram flour,
1 Rajasthan West 80 Boondi sweet vegetarian dessert
ghee, sugar
Carrots,
Gajar milk, sugar,
2 Punjab North 15 ka ghee, sweet vegetarian dessert
halwa cashews,
raisins
Flour, ghee,
kewra, milk,
3 Rajasthan West 15 Ghevar sweet vegetarian dessert
clarified
butter, su...
Milk
powder,
West Gulab plain flour,
4 East 15 sweet vegetarian dessert
Bengal jamun baking
powder,
ghee,...
Glutinous
North rice, black
250 Assam 5 Til Pitha sweet vegetarian dessert
East sesame
seeds, gur
Coconut
milk, egg
251 Goa West 20 Bebinca yolks, sweet vegetarian dessert
clarified
butter, all...
Cottage
cheese, dry
Jammu &
252 North -1 Shufta dates, dried sweet vegetarian dessert
Kashmir
rose petals,
...
Milk
powder, dry
Madhya Mawa fruits,
253 Central 20 sweet vegetarian dessert
Pradesh Bati arrowroot
powder,
all...
Brown rice,
fennel
seeds,
254 Goa West -1 Pinaca sweet vegetarian dessert
grated
coconut,
blac...
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 16/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
In [38]:
df.sort_index(axis=0,ascending=False)
Out[38]:
Brown rice,
fennel
seeds,
254 Pinaca vegetarian -1 -1 sweet dessert Goa
grated
coconut,
blac...
Milk
powder, dry
Mawa fruits, Madhya
253 vegetarian 20 45 sweet dessert C
Bati arrowroot Pradesh
powder,
all...
Cottage
cheese, dry
Jammu &
252 Shufta dates, dried vegetarian -1 -1 sweet dessert
Kashmir
rose petals,
...
Coconut
milk, egg
251 Bebinca yolks, vegetarian 20 60 sweet dessert Goa
clarified
butter, all...
Glutinous
rice, black
250 Til Pitha vegetarian 5 30 sweet dessert Assam
sesame
seeds, gur
Milk
powder,
Gulab plain flour, West
4 vegetarian 15 40 sweet dessert
jamun baking Bengal
powder,
ghee,...
Flour, ghee,
kewra, milk,
3 Ghevar vegetarian 15 30 sweet dessert Rajasthan
clarified
butter, su...
Carrots,
Gajar milk, sugar,
2 ka ghee, vegetarian 15 60 sweet dessert Punjab
halwa cashews,
raisins
Gram flour,
1 Boondi vegetarian 80 30 sweet dessert Rajasthan
ghee, sugar
Maida flour,
Balu West
0 yogurt, oil, vegetarian 45 25 sweet dessert
shahi Bengal
sugar
In [40]:
df[['state','name']]
Out[40]:
state name
1 Rajasthan Boondi
3 Rajasthan Ghevar
In [41]:
df['state']=='Goa' #it will return boolean True or False if the condition is true then true
Out[41]:
0 False
1 False
2 False
3 False
4 False
...
250 False
251 True
252 False
253 False
254 True
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 18/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
In [43]:
Chicken,
coconut oil,
non main
211 Vindaloo wine 10 40 spicy Goa Wes
vegetarian course
vinegar,
ginger, gr...
Coconut
milk, egg
251 Bebinca yolks, vegetarian 20 60 sweet dessert Goa Wes
clarified
butter, all...
Brown rice,
fennel
seeds,
254 Pinaca vegetarian -1 -1 sweet dessert Goa Wes
grated
coconut,
blac...
#we use isnull to check weather dataset is having missing values or not
#if True there are missing values else no missing values
df.isnull().values.any()
Out[44]:
True
In [45]:
#To check missing values for a specific row we use column name
df['state'].isnull().values.any()
Out[45]:
False
MATPLOTLIB
Matplotlib is an amazing visualization library in Python for 2D plots of arrays.
Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the
broader SciPy stack. It was introduced by John Hunter in the year 2002.
One of the greatest benefits of visualization is that it allows us visual access to huge amounts of data in
easily digestible visuals.
Matplotlib consists of several plots like line, bar, scatter, histogram etc
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 19/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
In [46]:
#importing matplotlib
import matplotlib.pyplot as plt
In [48]:
x = np.array([0,1,2,3,4,5,6]) #x avlues
y = np.array([0,2,4,5,6,7,8]) #y values
plt.plot(x,y) #it will plot between x and y
plt.show() #it will show the graph
In [49]:
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 20/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
In [50]:
plt.plot(x, y, '*')
plt.show()
plt.plot(x,y,'o')
plt.xlabel("Day")
plt.ylabel("Items sold")
plt.show()
Scatter Plot
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 21/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
In [52]:
x = np.array([1,2,3,4,5])
y = np.array([10,3,40,50,60])
plt.scatter(x, y) #it will gives us a scatter plot
plt.show()
Bar Graph
In [53]:
Pie Chart
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 22/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
In [54]:
y = np.array([11,33,56,43,18,34,12])
mylabels = ['a','b','c','d','e','f','g']
plt.pie(y, labels = mylabels, startangle = 90)
plt.show()
Box Plot
In [55]:
x = np.array([11,33,56,43,18,34,12])
plt.boxplot(x)
plt.show()
Histogrm
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 23/24
23/08/2021 AP19110010030_Assignmnet-1 - Jupyter Notebook
In [56]:
x = np.random.randn(100)
plt.hist(x, histtype = "step")
plt.show()
localhost:8888/notebooks/AP19110010030_Assignmnet-1.ipynb 24/24