0% found this document useful (0 votes)
32 views2 pages

Assignment1 VidulGarg

This document contains code for performing several tasks with a Pandas DataFrame containing randomly generated numeric data. Task 1 generates the random data and creates the DataFrame. Task 2 renames the column headers. Task 3 calculates descriptive statistics of the data. Task 4 checks for null values and prints the data types. Task 5 demonstrates indexing subsets of the data by column names and locations.

Uploaded by

vidulgarg1524
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

Assignment1 VidulGarg

This document contains code for performing several tasks with a Pandas DataFrame containing randomly generated numeric data. Task 1 generates the random data and creates the DataFrame. Task 2 renames the column headers. Task 3 calculates descriptive statistics of the data. Task 4 checks for null values and prints the data types. Task 5 demonstrates indexing subsets of the data by column names and locations.

Uploaded by

vidulgarg1524
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

AI ML Assignment 1

import pandas as pd
import numpy as np

Task 1
Data=np.random.rand(4,4)
df=pd.DataFrame(Data)
df

0 1 2 3
0 0.527877 0.965996 0.689760 0.489585
1 0.802960 0.147662 0.904135 0.725686
2 0.884734 0.972514 0.750256 0.270657
3 0.153342 0.552805 0.968987 0.326859

Task 2
df.columns = ['Random value 1', 'Random value 2', 'Random value 3',
'Random value 4']
df

Random value 1 Random value 2 Random value 3 Random value 4


0 0.527877 0.965996 0.689760 0.489585
1 0.802960 0.147662 0.904135 0.725686
2 0.884734 0.972514 0.750256 0.270657
3 0.153342 0.552805 0.968987 0.326859

Task 3
descriptive_stats = df.describe()
descriptive_stats

Random value 1 Random value 2 Random value 3 Random value 4


count 4.000000 4.000000 4.000000 4.000000
mean 0.592228 0.659744 0.828285 0.453197
std 0.330015 0.393818 0.130164 0.204007
min 0.153342 0.147662 0.689760 0.270657
25% 0.434243 0.451519 0.735132 0.312809
50% 0.665418 0.759401 0.827196 0.408222
75% 0.823404 0.967625 0.920348 0.548611
max 0.884734 0.972514 0.968987 0.725686

Task 4
print(df.isnull().sum())
data_types = df.dtypes
print("\n")
print(data_types)

Random value 1 0
Random value 2 0
Random value 3 0
Random value 4 0
dtype: int64

Random value 1 float64


Random value 2 float64
Random value 3 float64
Random value 4 float64
dtype: object

Task 5
# Using location indexing
df.iloc[:,1:3]

Random value 2 Random value 3


0 0.965996 0.689760
1 0.147662 0.904135
2 0.972514 0.750256
3 0.552805 0.968987

# Using column name (indexing)


second = df['Random value 2']
third = df['Random value 3']
print(second)
print(third)

0 0.965996
1 0.147662
2 0.972514
3 0.552805
Name: Random value 2, dtype: float64
0 0.689760
1 0.904135
2 0.750256
3 0.968987
Name: Random value 3, dtype: float64

You might also like