0% found this document useful (0 votes)
5 views

Python Exercise

The document discusses implementing pandas operations on various datasets. It converts a NumPy array to a pandas series and calculates the frequency counts of unique values in a series. It reads the diamonds dataset from a CSV file and prints the first 6 rows of selected columns. It displays the shape and data types of columns in the diamonds dataframe. Overall, the document demonstrates various pandas operations on arrays, series, and dataframes including data wrangling, aggregation, and exploration.

Uploaded by

sailesh lal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Python Exercise

The document discusses implementing pandas operations on various datasets. It converts a NumPy array to a pandas series and calculates the frequency counts of unique values in a series. It reads the diamonds dataset from a CSV file and prints the first 6 rows of selected columns. It displays the shape and data types of columns in the diamonds dataframe. Overall, the document demonstrates various pandas operations on arrays, series, and dataframes including data wrangling, aggregation, and exploration.

Uploaded by

sailesh lal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Register Number:61781922110041

Ex. No:3
IMPLEMENTATION OF PANDAS AND ITS OPERATIONS
Date:

U19ADS2035- PYTHON FOR DATA SCIENCE LABORATORY Page No:12


Register Number:61781922110041

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)

U19ADS2035- PYTHON FOR DATA SCIENCE LABORATORY Page No:13


Register Number:61781922110041

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]

U19ADS2035- PYTHON FOR DATA SCIENCE LABORATORY Page No:14


Register Number:61781922110041

[0.17722071 0.53881772 0.57870175]


[0.63272873 0.99239438 0.1117528 ]]
[[0.08968437 0.70518266 0.42497186]
[0.17722071 0.53881772 0.57870175]
[0.63272873 0.99239438 0.1117528 ]]
[[4 9 6]
[7 8 5]
[3 8 0]]
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
List to Numpy Array:
[ 1 2 3 4 5 6 7 8 9 10]
[1 2 3 4 5]
[ 6 7 8 9 10]
[3 4 5]
[1 3 5 7 9]
[ 2 4 6 8 10]
[10 9 8 7 6 5 4 3 2 1]
Arithmetic Operation:
[ 3 4 5 6 7 8 9 10 11 12]
[-1 0 1 2 3 4 5 6 7 8]
[ 2 4 6 8 10 12 14 16 18 20]
[0.5 1. 1.5 2. 2.5 3. 3.5 4. 4.5 5. ]
Multidimensional Array:
[[1 2 3]
[4 5 6]
[7 8 9]]
[1 2 3]
[4 5 6]

U19ADS2035- PYTHON FOR DATA SCIENCE LABORATORY Page No:15


Register Number:61781922110041

[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]

U19ADS2035- PYTHON FOR DATA SCIENCE LABORATORY Page No:16

You might also like