L-1 (Introduction To Numpy & Panda) - Colab
L-1 (Introduction To Numpy & Panda) - Colab
import numpy as np
data1=[2,3,4,5]
arr1= np.array(data1)
print(arr1)
[2 3 4 5]
data1=[[2,3,4,5],[34,45,56,30]]
arr2=np.array(data1)
print(arr2)
[[ 2 3 4 5]
[34 45 56 30]]
print(arr2.ndim)
print(arr2.shape)
print(arr2.dtype)
2
(2, 4)
int64
arr1=np.zeros(10)
arr2=np.zeros((3,6))
print("1d array of Zeros:",arr1)
print("2d array of Zeros")
print(arr2)
arr1=np.arange(15)
arr2=np.arange(15).reshape(3,5)
print("1d array of sequence:",arr1)
print("2d array of sequence")
print(arr2)
a1 = np.random.rand(7)
print("1D:",a1)
a2 = np.random.rand(2,4)
https://colab.research.google.com/drive/1L_nq3557ODX9-DPKl7K2qHZwuY-BUC-8#printMode=true 1/7
3/14/25, 4:34 PM L-1 (Introduction to Numpy & Panda) - Colab
print("2D:",a2)
print()
print("1D and 2D Array of Random Integer Values")
a3 = np.random.randint(7,size=(5))
print("1D:",a3)
a4 = np.random.randint(7, size=(2,4))
print("2D:",a4)
print(arr1[5:8])
print(arr1[:])
print(arr1[1:])
print(arr1[4:])
print(arr1[:3])
[5 6 7]
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14]
[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14]
[ 4 5 6 7 8 9 10 11 12 13 14]
[0 1 2]
print("original array")
print(arr2)
print("0th row : all columns")
print(arr2[0,:])
print("all rows : 1st columns")
print(arr2[:,1])
print("1 to last rows : 2 to last columns")
print(arr2[1:,2:])
original array
[[ 0 1 2 3 4]
[ 5 6 7 8 9]
[10 11 12 13 14]]
0th row : all columns
[0 1 2 3 4]
all rows : 1st columns
[ 1 6 11]
1 to last rows : 2 to last columns
[[ 7 8 9]
[12 13 14]]
import pandas as pd
s1=pd.Series([2,3,4,5])
print(s1)
0 2
1 3
2 4
https://colab.research.google.com/drive/1L_nq3557ODX9-DPKl7K2qHZwuY-BUC-8#printMode=true 2/7
3/14/25, 4:34 PM L-1 (Introduction to Numpy & Panda) - Colab
3 5
dtype: int64
s1=pd.Series([2,3,4,5], index=['a','b','c','d'])
s2 = pd.Series([1000,2000,-1000,-5000,1000],index = ['a', 'b', 'c', 'd', 'e'])
s3 = pd.Series([10,20,-10,-50,100], index = ['z', 'y', 'a', 'c', 'e'])
print(s1)
print(s2)
print(s3)
a 2
b 3
c 4
d 5
dtype: int64
a 1000
b 2000
c -1000
d -5000
e 1000
dtype: int64
z 10
y 20
a -10
c -50
e 100
dtype: int64
arr4=pd.Series(np.arange(5),index=['a','b','c','d','e'])
print(arr4)
a 0
b 1
c 2
d 3
e 4
dtype: int64
dic1={'one':23,'two':34,'three':45}
s2=pd.Series(dic1)
print(s2)
one 23
two 34
three 45
dtype: int64
arr5=arr4.drop('d')
print(arr5)
a 0
b 1
c 2
e 4
dtype: int64
arr5=arr4.drop(['a','d'])
print(arr5)
b 1
c 2
e 4
dtype: int64
Data Frame
https://colab.research.google.com/drive/1L_nq3557ODX9-DPKl7K2qHZwuY-BUC-8#printMode=true 3/7
3/14/25, 4:34 PM L-1 (Introduction to Numpy & Panda) - Colab
0 Delhi
1 is
2 the
3 capital
4 of
5 India
WORDS
a Delhi
b is
c the
d capital
e of
f India
pandas.core.frame.DataFrame
n1 n2 n3
a 0 1 2
b 3 4 5
c 6 7 8
s1=pd.Series([2,3,4,5,6])
s2 = pd.Series([1000,2000,-1000,-5000,1000])
s3 = pd.Series([10,20,-10,-50,100])
df = pd.DataFrame([s1, s2, s3] )
print(df)
0 1 2 3 4
0 2 3 4 5 6
1 1000 2000 -1000 -5000 1000
2 10 20 -10 -50 100
s1=pd.Series([2,3,4,5,6], index=['a','b','c','d','e'])
s2 = pd.Series([1000,2000,-1000,-5000,1000],index = ['a', 'b', 'c', 'd', 'e'])
s3 = pd.Series([10,20,-10,-50,100], index = ['z', 'y', 'a', 'c', 'e'])
df = pd.DataFrame([s1, s2, s3] )
print(df)
a b c d e z y
0 2.0 3.0 4.0 5.0 6.0 NaN NaN
1 1000.0 2000.0 -1000.0 -5000.0 1000.0 NaN NaN
2 -10.0 NaN -50.0 NaN 100.0 10.0 20.0
https://colab.research.google.com/drive/1L_nq3557ODX9-DPKl7K2qHZwuY-BUC-8#printMode=true 4/7
3/14/25, 4:34 PM L-1 (Introduction to Numpy & Panda) - Colab
0 1
0 a 20
1 b 25
2 c 35
3 d 60
Nevada Ohio
2001 2.4 1.7
2002 2.9 3.6
2000 NaN 1.5
Mounted at /content/drive
Name Gender MonthlyIncome
https://colab.research.google.com/drive/1L_nq3557ODX9-DPKl7K2qHZwuY-BUC-8#printMode=true 5/7
3/14/25, 4:34 PM L-1 (Introduction to Numpy & Panda) - Colab
df.T
0 1 2 3 4 5 6 7 8 9
Name Shah Vats Vats Kumar Vats Kumar Shah Shah Kumar Vats
Gender Male Male Female Female Female Male Male Female Female Male
MonthlyIncome 114000 65000 43150 69500 155000 103000 55000 112400 81030 71900
df['age']=[40,30,40,40,30,45,50,25,30,30]
df
df.index = ['f1','f2','f3','f4','f5','f6','f7','f8','f9','f10']
df
df.columns=["NAME","GENDER","MONTHLY_INCOME","AGE"]
df
https://colab.research.google.com/drive/1L_nq3557ODX9-DPKl7K2qHZwuY-BUC-8#printMode=true 6/7
3/14/25, 4:34 PM L-1 (Introduction to Numpy & Panda) - Colab
https://colab.research.google.com/drive/1L_nq3557ODX9-DPKl7K2qHZwuY-BUC-8#printMode=true 7/7