Python programming U5
Python programming U5
**Creation of Arrays**: -
`numpy.array`: Create an array from a Python list or tuple. –
**Array Manipulation**: -
`numpy.reshape`: Reshape an array. –
**Mathematical Operations**: -
`numpy.sum`: Sum of array elements. –
import numpy as np
arr=np.array(
[
[34,56,23,78],
[23,856,234,23],
[53,45,67,879]
])
for i in range(3):
for j in range(4):
print(arr[i][j],end=" ")
print()
#Creating 2/3 Dimensional array from 1 Dimensional array using
reshape
import numpy as np
#arr=np.zeros((5,4))
arr=np.array([23,45,67,23,56,89,56,23,45,789,56,123])
arr1=arr.reshape(3,4)
print(arr)
print()
print(arr1)
arr2=arr.reshape(4,3)
print(arr2)
print()
arr3=arr.reshape(2,3,2)
print(arr3)
import numpy as np
arr=np.array([23,45,67,23,56,89,56,23,45,789,56,123])
#arr1=np.sqrt(arr)
arr1=np.log(arr)
print(arr)
print(arr1)
Exercise(RRSIMT CLASSES)
1) Create a Program in Python Reverse the Array
without using Library Functions.
2) Create a Program in Python find the Min and Max
Value of an Array without using Library Functions.
3) Create a Program in Python to Reverse the Array.
4) Create a Program in Python to Implement Bubble
Sort on an Array.
5) Create a Program in Python to Implement Selection
Sort on an Array.
6) Create a Program in Python to Implement Merge
Sort on an Array.
7) Create a Program in Python to Transpose the
Matrix. 8) Create a Program in Python to Sum of Two
Matrix.
9) Create a Program in Python to Multiply the Matrix.
10) Create a Program in Python to Generate the OTP
of 6 Digits.
"Sample.csv"
EID,Ename,Post,Department,Salary
1,Rakesh Kumar,Manager,Sales,35000
2,Sanjeev Kumar,Executive,Marketing,21500
3,Amar Singh,Executive,Sales,27000
4,Sumit Bansal,Manager,Marketing,32500
5,Harish Kumar,Executive,Account,22000
6,Akash,Executive,Account,25000
7,Ajeet,Manager,Account,31500
8,Rajesh,Manager,Production,35000
9,Amit Gupta,Executive,Account,19000
10,Atul,Executive,Production,24000
#programs to read csv file to create dataframe and sort salary column
ascending and descending
import pandas as pd
df=pd.read_csv("sample.csv")
df1=df.sort_values(by='Salary')
print(df1)
df1=df.sort_values(by='Salary',ascending=False)
print(df1)
#programs to read csv file to create dataframe and then locate rows.
import pandas as pd
df=pd.read_csv("sample.csv")
#print(df.loc[3])
print(df.loc[5:7])