0% found this document useful (0 votes)
5 views3 pages

Practical - 7 (22ss02ca057)

Uploaded by

glicmack
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)
5 views3 pages

Practical - 7 (22ss02ca057)

Uploaded by

glicmack
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/ 3

Name: Prince Vekariya

En. No.: 22ss02ca057

Subject: Data Science

Subject code: SSCA3021

Code:

import pandas as pd
import numpy as np

# 1. Display a summary of the basic information about a specified DataFrame


and its data
exam_data = {
'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael',
'Matthew', 'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no',
'yes']
}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
df = pd.DataFrame(exam_data, index=labels)

print("Summary of the DataFrame:")


print(df.info())

print("\nDataFrame:")
print(df)

# 2. Create a DataFrame as mentioned in the provided image (fig-1)


data = {
'First_name': ['Ram', 'Mohan', 'Tina', 'Jeetu', 'Meera'],
'Last_name': ['Kumar', 'Sharma', 'Ali', 'Gandhi', 'Kumari'],
'Age': [42, 52, 36, 21, 23],
'City': ['Mumbai', 'Noida', 'Pune', 'Delhi', 'Bihar'],
'Qualification': ['B.Com', 'IAS', 'LLB', 'B.Tech', 'MBBS']
}
df_image = pd.DataFrame(data)

print("\nDataFrame as per the provided image:")


print(df_image)

# 3. Replace some of the values of the DataFrame


df_image_replaced = df_image.replace({
'First_name': {'Ram': 'Shyam', 'Tina': 'Riya', 'Jeetu': 'Jitender'}
})

print("\nModified DataFrame with replaced values:")


print(df_image_replaced)

# 4. Select the rows where the number of attempts in the examination is


greater than 2
df_attempts_greater_than_2 = df[df['attempts'] > 2]

print("\nRows where the number of attempts is greater than 2:")


print(df_attempts_greater_than_2)

Code:

You might also like