Python Exercise
Python Exercise
Ex. No:3
IMPLEMENTATION OF PANDAS AND ITS OPERATIONS
Date:
PROGRAM:
import pandas as pd
import numpy as np
#3a.Convert a NumPy array to a Pandas series. Also write a Pandas program to calculate the
#equency counts of each unique value of a given series.
a=np.arange(10)
print("Numpy array:\n",a)
b=pd.Series(a)
print("Pandas Series:\n",b)
aa=[1,2,3,4,5,6,7,8,9,1,3,4,5,6,7]
bb=pd.Series(aa)
print(bb)
print(bb.nunique())
#3b. Read a dataset aom diamonds DataFrame and modify the default columns values and print
the £rst 6 rows.
user_cols = ['carat', 'cut', 'x', 'y', 'z']
diamonds = pd.read_csv('C://Users//naveen//Pictures//archive (6)//diamonds.csv')
print(diamonds.head())
print("First 6 rows:")
print(diamonds[user_cols].head(6))
#3b. BIrd the number of rows and columns and data type of each column of diamonds DataFrame.
print(diamonds.shape)
print(diamonds.dtypes)
OUTPUT:
Numpy Array Creation:
[ 1 2 3 4 5 6 7 8 9 10] 6
(10,)
[ 1 2 3 4 5 6 7 8 9 10] 6
(10,)
[3.2 4. 6. 5. ] 3.2
(4,)
[1 4 2 5 3]
(5,)
['1' '2' '3' '4']
[1. 2. 3. 4.]
[[2 3 4]
[4 5 6]
[6 7 8]]
(3, 3)
[0 0 0 0 0 0 0 0 0 0]
[[0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0.]]
[[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]]
[[3.14 3.14 3.14 3.14 3.14]
[3.14 3.14 3.14 3.14 3.14]
[3.14 3.14 3.14 3.14 3.14]]
[0. 0.25 0.5 0.75 1. ]
[[0.08968437 0.70518266 0.42497186]
[7 8 9]
[[ True True True]
[ True True True]
[False False False]]
[[False False False]
[False True True]
[ True True True]]
[[False False False]
[False True False]
[False False False]]
Union of Two Arrays:
[ 1 2 3 4 5 6 7 8 9 10 11 14 15 16 18 19]