Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

Practical_File (1)

it contains project file requirements

Uploaded by

abhideol09
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Practical_File (1)

it contains project file requirements

Uploaded by

abhideol09
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

PRACTICAL FILE

Data Visualization
Bar-Graph

Output
Pie-Chart
Histogram
Numpy Programs

1. WAP to swap first two columns in a 2D numpy array?

Ans:

import numpy as np

arr = np.arange(9).reshape(3,3)

print(arr)

print(arr[:, [1,0,2]])

2. WAP to swap first two rows in a 2D numpy array?

Ans:

import numpy as np

arr = np.arange(9).reshape(3,3)
print(arr)
print(arr[[1,0,2], :])
3. WAP to reverse the columns in a 2D numpy array?

Ans:

import numpy as np

arr = np.arange(9).reshape(3,3)

print(arr)

print(arr[:, ::-1])

4. WAP to subtract the mean from each row of a 5*5 array.

Ans:

import numpy as np

X = np.arange(25).reshape(5,5)

print(X)

print(X.mean(axis=1))

Y = X - X.mean(axis=1)

print(Y)
5. WAP to Create a 4X2 integer array and Prints its attributes
The element must be a type of unsigned int16. And print the
following Attributes: –

The shape of an array.


Array dimensions.
The Length of each element of the array in bytes.
Ans:
import numpy as np
A=np.zeros([4,2], dtype =int)
print("Printing Array")
print(A)

print("Printing numpy array Attributes")


print("1> Array Shape is: ", A.shape)
print("2>. Array dimensions are ", A.ndim)
print("3>. Length of each element of array in bytes is ", A.itemsize)
Data-Frame
1.
import pandas as pd

student = {
'Name':['Ashish','Aklesh','Suman','Sushm
a'], 'Age': [15,18,17,16],
'Marks':[70,90,85,65],
'Gender': ['M','M','F','F']
}

df_dict = pd.DataFrame(student,index =
[1,2,3,4]) df_dict

[19] Name Age Marks Gender


1 Ashish 15 70 M
2 Aklesh 18 90 M
3 Suman 17 85 F
4.Sushma 16 65 F
2.

import pandas as pd

student = [
{'Name':'Ashish', 'Age':15,'Marks':70,'Gender':'M'},
{'Name':'Aklesh', 'Age':18,'Marks':90,'Gender':'M'},
{'Name':'Suman', 'Age':17,'Marks':85,'Gender':'F'},
{'Name':'Sushma', 'Age':16,'Marks':65,'Gender':'F'}
]

df_list_dict = pd.DataFrame(student)
df_list_dict
[20] Name Age Marks Gender
0 Ashish 15 70 M
1 Aklesh 18 90 M
2 Suman 17 85 F
3 Sushma 16 65 F

3.

import pandas as pd
emp = {
'Name':['Ramesh','Suresh','Sumukhi','Tanmay','Biswa'],
'Department': ['Logistics','Logistics','Creative','Creative','Editorial'],
'Salary': [50000,60000,45000,60000,50000],
'Location': ['Delhi','Mumbai','Mumbai','Hyderabad','Kolkata']}
Employee = pd.DataFrame(emp)
Employee
[2] Output:
[3] Name Department Salary Location
0 Ramesh Logistics 50000 Delhi
1 Suresh Logistics 60000 Mumbai
2 Sumukhi Creative 45000 Mumbai
3 Tanmay Creative 60000 Hyderabad
4 Biswa Editorial 50000 Kolkata
4.

import pandas as pd

player = {'Name': ['Rohit', 'Smith','Warner', 'Sachin', 'Morgan'],


'Country': ['India',
'Australia','Australia','India','England'],
'Role:': ['Bat','Bat','Bat','Bat','Bat'],
'Batting Hand': ['R','R','L','R','L']}
Player_df = pd.DataFrame(player)
Player_df.loc[len(Player_df)] = ['Russel','West Indies','Bat','R']
Player_df.loc[len(Player_df)] = ['Dhoni','India','WK','R']
Player_df.loc[len(Player_df)] = ['Paine','Australia','WK','R']
Player_df.loc[len(Player_df)] = ['Archer','England','Bowler','R']
Player_df.loc[len(Player_df)] = ['Stark','Australia','Bowler','L']

idx = Player_df.loc[Player_df.Country ==
"Australia"].index Player_df.drop(idx, axis = 0, inplace =
True)
Player_df

5.
import pandas as pd

player = {'Name': ['Rohit', 'Smith','Warner', 'Sachin', 'Morgan'],


'Country': ['India',
'Australia','Australia','India','England'],
'Role:': ['Bat','Bat','Bat','Bat','Bat'],
'Batting Hand': ['R','R','L','R','L']}
Player_df = pd.DataFrame(player)
Player_df.loc[len(Player_df)] = ['Russel','West Indies','Bat','R']
Player_df.loc[len(Player_df)] = ['Dhoni','India','WK','R']
Player_df.loc[len(Player_df)] = ['Paine','Australia','WK','R']
Player_df.loc[len(Player_df)] = ['Archer','England','Bowler','R']
Player_df.loc[len(Player_df)] = ['Stark','Australia','Bowler','L']
Player_df.rename({0:'Open 1',1: 'Open 2', 2: '1 Down', 3: '2 Down',
4: '3␣
‹→Down', 5: '4 Down',
6: '5 Down',7: '6 Down',8: '7 Down', 9:'8 Down'}, axis
= 0,␣
‹→inplace = True)
Player_df.rename({'Name':'Player Name','Role:':'Role'}, axis = 1,
inplace =␣
‹→True)
print(Player_df)

Player Name Country Role Batting Hand


1
Open 1 Rohit India Bat R
Open 2 Smith Australia Bat R
1 Down Warne Australia Bat L
r
2 Down Sachin India Bat R
3 Down Morga England Bat L
n
4 Down Russel West Bat R
Indies
5 Down Dhoni India WK R
6 Down Paine Australi WK R
a
7 Down Archer England Bowl R
er
8 Down Stark Australi Bowl L
a er
Series
1.
import pandas as pd

data = [10,20,30,40,50]
list_series =
pd.Series(data)
print(list_series)
0 10
1 20
2 30
3 40
4 50
dtype: int64

2.
import pandas as pd
data = 10
scalar_series =
pd.Series(data)
print('Scalar Series')
print(scalar_series)
scalar_series2 = pd.Series(data, index =
[1,2,3,4,5]) print('\nScalar Series with
Multiple Index') print(scalar_series2)

Scala
r
Serie
s0
1
0
dtype: int64
Scalar Series with
Multiple Index 1 10
2 10
3 10
4 10
5 10
dtype: int64

3.

import pandas as pd

days = [31,28,31,30,31]
calender = pd.Series(days,index =
['Jan','Feb','Mar','Apr','May']) print("Entire
Calender")
print(calen
der) print()
print('Using Labeled Indexing')
# Using Labeled
Indexing print("No of
days in Apr")
print(calender['Apr'])
print()
# Using Positional Indexing
print('Using Positional Indexing')
print("No of Days in the 4th Month (3rd
Position)") print(calender[3])

Entire
Calend
er Jan
3
1
Feb 28
Mar 31
Apr 30
May 31
dtype: int64
4.

l1 = [1,4,33,16,9,22,21,28,45,27,90]
S = pd.Series(l1)
print(S)
print()
print("Elements those are a multiple of
3") print(S.loc[S%3 ==0])
import pandas as pd

S1 = pd.Series([5,20,35,40,50],index = [1,4,7,8,10])
print(S1)
print()
print('Labeled Index 4')
print(S1.loc[4])
#print(S1[
4]) print()

print('Labeled Index 5')


print('S1.loc[5] will give Key
Error.') print()
print("Positional Index
4") print(S1.iloc[4])
1 5
4 20
7 35
8 40
10 50
dtype: int64
Labeled Index 4
20

Labeled Index 5
5.

import pandas as pd

student = {'Raj': 80, 'Rahul': 65, 'Vijay':75, 'Karan':45,

'Shikha':90} Student_Series = pd.Series(student)

print(Student_Ser
ies) print()
print("Find those students who have scored more than 70 Marks.")
#loc property
print(Student_Series.loc[Student_Series>70])

Raj 80
Rah 65
ul
Vija 75
y
Kara 45
n
Shik 90
ha
dtyp int6
e: 4

You might also like