0% found this document useful (0 votes)
40 views4 pages

Assignment 1 (Set A)

FDS practical answers

Uploaded by

indalkaranuja2
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)
40 views4 pages

Assignment 1 (Set A)

FDS practical answers

Uploaded by

indalkaranuja2
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

#1.

Write a Python program to create a dataframe containing columns name, age and percentage Add 10 rows to the datafr

import pandas as pd
df = [Link](columns = ["name", "age", "percentage"])

[Link][0] = ["Riya", 15, 80]


[Link][1] = ["Priya", 20, 89]
[Link][2] = ["Tiya", 21, 77]
[Link][3] = ["Kriya", 19, 90]
[Link][4] = ["Alice", 22, 98]
[Link][5] = ["Bob", 27, 78]
[Link][6] = ["Mike", 24, 99]
[Link][7] = ["Richeal", 25, 80]
[Link][8] = ["Harvey", 30, 100]
[Link][9] = ["Donna", 29, 100]

df

name age percentage

0 Riya 15 80

1 Priya 20 89

2 Tiya 21 77

3 Kriya 19 90

4 Alice 22 98

5 Bob 27 78

6 Mike 24 99

7 Richeal 25 80

8 Harvey 30 100

9 Donna 29 100

#[Link] a Python program to print the shape, number of rows-columns, data types, feature names and the description o

import pandas as pd

df = [Link](columns = ["Name", "Class"])

[Link][0] = ["Jessica", 9]
[Link][1] = ["samantha", 10]
[Link][2] = ["lewis", 7]
[Link][3] = ["Danieal", 5]
[Link][4] = ["robert", 12]

print("[Link] of rows and coulmns in the above program is:",[Link])


print("\[Link] of above program is:", type(df))
print("\[Link] of above program is:", type([Link][0]))
print("\[Link] of the above program is:\n", [Link])

[Link] of rows and coulmns in the above program is: (5, 2)

[Link] of above program is: <class '[Link]'>

[Link] of above program is: <class '[Link]'>

[Link] of the above program is:


<bound method [Link] of Name Class
0 Jessica 9
1 samantha 10
2 lewis 7
3 Danieal 5
4 robert 12>

#3. Write a Python program to view basic statistical details of the data.

import pandas as pd
df = [Link](columns = ["Name", "designation", "marks"])

[Link][0] = ["Julie", "Web Devloper", 89]


[Link][1] = ["Peter", "Game Devloper", 76]
[Link][2] = ["Thomas", "HR", 66]
[Link][3] = ["Neo", "Senior partner", 90]
[Link][4] = ["Agotha", "Managing partner", 100]

print("basic statistical operations:\n")


[Link]()
basic statistical operations:

marks

count 5.000000

mean 84.200000

std 13.274035

min 66.000000

25% 76.000000

50% 89.000000

75% 90.000000

max 100.000000

#[Link] a Python program to Add 5 rows with duplicate values and missing values. Add a column ‘remarks’ with empty v

import pandas as pd
import numpy as np
data = {
"Name": ["Alice", "Bob", "Charlie", "Alice", None],
"Class": [10, 9, None, 10, 12]}
df = [Link](data)
df["remarks"] = ""
print("DataFrame with duplicate, missing, and empty remark column:\n")
df

DataFrame with duplicate, missing, and empty remark column:

Name Class remarks

0 Alice 10.0

1 Bob 9.0

2 Charlie NaN

3 Alice 10.0

4 None 12.0

#5. Write a Python program to get the number of observations, missing values and duplicate values.
import pandas as pd
data = {
'Name': ['Alice', 'Bob', 'Charlie', 'Mike', None],
'Age': [25, None, 30, 25, 22],
'City': ['Pune', 'Mumbai', 'Delhi', 'Nagpur', 'Pune']}
df = [Link](data)
observations = len(df)
missing_val = [Link]().sum().sum()
duplicates_val = [Link]().sum()
print("Number of observations:", observations)
print("Number of missing values:", missing_val)
print("Number of duplicate values:",duplicates_val)

Number of observations: 5
Number of missing values: 2
Number of duplicate values: 0

#[Link] a Python program to drop ‘remarks’ column from the dataframe. Also drop all null and empty values. Print the

import pandas as pd
data_1 = {"Name" : ["Harvey", "Donna", "Reachel", "Sam", None], "Age":[43, 40, None, 30, 25], "Remark" : ["", "", ""
df = [Link](data_1)
df = [Link](columns = "Remark")
df = [Link]("", None)
df = [Link]()
print("Updated data:\n")
df

Updated data:

Name Age

0 Harvey 43.0

1 Donna 40.0

3 Sam 30.0

#7. Write a Python program to generate a line plot of name vs percentage.


import pandas as pd
import [Link] as plt
df = [Link](columns = ["Name", "age", "Percentage"])
[Link][0] = ["Riya", 15, 80]
[Link][1] = ["Priya", 20, 89]
[Link][2] = ["Tiya", 21, 77]
[Link][3] = ["Kriya", 19, 90]
[Link][4] = ["Alice", 22, 98]
[Link][5] = ["Bob", 27, 78]
[Link][6] = ["Mike", 24, 99]
[Link][7] = ["Richeal", 25, 80]
[Link][8] = ["Harvey", 30, 100]
[Link][9] = ["Donna", 29, 100]

[Link](x = "Name", y = "Percentage", kind = "line")


[Link]("Name")
[Link]("Percentage")
[Link]("Name VS Percentage plot.")

Text(0.5, 1.0, 'Name VS Percentage plot.')

#8. Write a Python program to generate a scatter plot of name vs percentage


import pandas as pd
import [Link] as plt
df = [Link](columns = ["Name", "age", "Percentage"])
[Link][0] = ["Riya", 15, 80]
[Link][1] = ["Priya", 20, 89]
[Link][2] = ["Tiya", 21, 77]
[Link][3] = ["Kriya", 19, 90]
[Link][4] = ["Alice", 22, 98]
[Link][5] = ["Bob", 27, 78]
[Link][6] = ["Mike", 24, 99]
[Link][7] = ["Richeal", 25, 80]
[Link][8] = ["Harvey", 30, 100]
[Link][9] = ["Donna", 29, 100]

[Link](x = "Name", y = "Percentage", kind = "scatter")


[Link]("Name")
[Link]("Percentage")
[Link]("Name VS Percentage scatter plot.")

Text(0.5, 1.0, 'Name VS Percentage scatter plot.')


Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/[Link]

You might also like