Exp_1_Introduction to Data Analytics and Python fundamentals_sdk_ok
Exp_1_Introduction to Data Analytics and Python fundamentals_sdk_ok
No : 01
#Name:____________________________________
#Class: S.E (E & TC) Roll No: _________________
#Subject: Python – Data Analytics Lab.
OUTPUT:
OUTPUT:
Import numpy as np
a=np.array([[1,2],[3,4]])
b=np.array([[4,3],[2,1]])
#Add Arrays
print("Array Sum:\n", a+b)
#Multiply Arrays
print("Array Multiplication:\n", a*b)
#Matrix Multiplication
print("Matrix Multiplication:\n", a.dot(b))
OUTPUT:
Array Sum:
[[5 5]
[5 5]]
Array Multiplication:
[[4 6]
[6 4]]
Matrix Multiplication:
[[ 8 5] [20 13]]
OUTPUT:
Array created using passed list:
[[1 2 4]
[5 8 7]]
Original Array:
[[4,5,6,2]
[1,2,3,4]
[1,5,0,4]]
Reshaped Array:
[[4,5,6]
[2,1,2]
[3,4,1]
[5,4,0]]
Original Array:
[[1 2 3]
[4 5 6]]
Flattened Array:
[1 2 3 4 5 6]
# Python program to demonstrate unary operators in numpy
import numpy as np
arr = np.array([[1, 5,
6],
[4, 7, 2],
[3, 1, 9]])
# maximum element of array
print ("Largest element is:", arr.max())
print ("Row-wise maximum elements:",arr.max(axis = 1))
# minimum element of array
print ("Column-wise minimum elements:",arr.min(axis = 0))
# sum of array elements
print ("Sum of all array elements:",arr.sum())
OUTPUT:
Name Age
0 Alex 10.00
1 Bob 12.00
2 Clarke 13.00
OUTPUT:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3 entries, 0 to 2
Data columns (total 2 columns):
# Column Non-Null Count Dtype
--- ---- --- --- --- --- --- --- --- --- ---
0 Name 3 non-null object
1 Age 3 non-null float64
dtypes:
float64(1),object(1)
memory usage:
176.0+ bytes None
#Calculating Some Statistical Data like Percentile, Mean and Std of the
Numerical
print ( df.describe () )
Age
Count 3.000000
Mean 11.666667
Std 1.527525
Min 10.000000
25% 11.000000
50% 12.000000
75% 12.000000
max 13.000000
#Selecting Coloumn
Print( df [‘Name’])
OUTPUT:
0 Alex
1 Bob
2 Clarke
Name: Name,
dtype:object
#Selecting Row
Print (df. Iloc [2] )
OUTPUT:
Name Clarke
Age 13
Name: 2, dtype:object
import sqlite3
conn=sqlite3.connect('example
.db')
c = conn.cursor()
# Create table c.execute
('''CREATE TABLE
stock(date text, trans
text, symbol text, qty
real, price real)''')
# Insert a row of data
c.execute("INSERT INTO stock VALUES ('2006-01-05','BUY','RHAT',100,35.14)")
c.execute("INSERT INTO stock VALUES ('2006-03-28', 'BUY', 'IBM', 1000, 45.00)")
c.execute("INSERT INTO stock VALUES ('2006-04-05', 'BUY', 'MSFT', 1000, 72.00)")
# Save (commit) the
changes
conn.commit()
for row in c.execute('SELECT * FROM stock ORDER BY
price'): print(row)
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
conn.close()
OUTPUT:
('2006-01-05', 'BUY', 'RHAT', 100.0, 35.14)
('2006-03-28', 'BUY', 'IBM', 1000.0, 45.0)
('2006-04-05', 'BUY', 'MSFT', 1000.0, 72.0)