Professional Documents
Culture Documents
E23MCAG0044 Lab1
E23MCAG0044 Lab1
import pandas as pd
In [26]: # Part 1: Perform the following operation on user created data using NumPy Lib
In [28]: # 1. Create the following Matrix and Perform the following operations on mat1 and mat2 using NumPy
mat1 = np.array([[10,20,30],[5,6,9],[11,15,17]])
mat2 = np.array([[1,20,3],[5,6,9],[2,1,3]])
print("1st matrix :\n",mat1)
print("\n2nd matrix :\n",mat2)
1st matrix :
[[10 20 30]
[ 5 6 9]
[11 15 17]]
2nd matrix :
[[ 1 20 3]
[ 5 6 9]
[ 2 1 3]]
Dot product :
[[170 350 300]
[ 53 145 96]
[120 327 219]]
In [19]: # Find the Min and Max element from the Mat1
print("max of mat1 :",np.max(mat1))
print("min of mat2 :",np.min(mat1))
max of mat1 : 30
min of mat2 : 5
In [22]: # Find the product and sum of the element of the mat1 and mat2
print("product of the element of the mat1 :",np.product(mat1))
print("sum of the element of the mat1 :",np.sum(mat1))
print("product of the element of the mat2 :",np.product(mat2))
print("sum of the element of the mat2 :",np.sum(mat2))
In [29]: # Part 2: Perform the following operation on user created data using Pandas Lib
In [85]: list1={"Hero":[1,5,6.6,8,6,13,6.6],"TVS":[11,13.4,18,9,16,13,18],"Honda":[26.6,50,80,None,1,0,80]}
index = ["Madhavi","Pranav","Bhagya","Param","Gauri","Anand","Bhagya"]
data1 = pd.DataFrame(list1,index)
data1
(7, 3)
Out[39]:
In [53]: # Extract the data of Hero column into variable X (Using Index, Label and Location) and convert it into
# NumPy array
By_index = np.array(data1.iloc[0:,:1])
By_label = np.array(data1.Hero)
print(By_index)
[[ 1. ]
[ 5. ]
[ 6.6]
[ 8. ]
[ 6. ]
[13. ]
[ 6.6]]
In [91]: # 3. Perform operations like row/ column removal from the above-created data frame.
data1.drop('Honda',axis=1)
Hero 0
Out[87]:
TVS 0
Honda 1
dtype: int64
In [88]: data1
In [94]: # 7. Store the pre-processed data in an external file named "My_Data.csv" (5)
data1.to_csv("E23MCAG0044.csv")
In [ ]: