Practical_File (1)
Practical_File (1)
Data Visualization
Bar-Graph
Output
Pie-Chart
Histogram
Numpy Programs
Ans:
import numpy as np
arr = np.arange(9).reshape(3,3)
print(arr)
print(arr[:, [1,0,2]])
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])
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: –
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
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
idx = Player_df.loc[Player_df.Country ==
"Australia"].index Player_df.drop(idx, axis = 0, inplace =
True)
Player_df
5.
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()
Labeled Index 5
5.
import pandas as pd
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