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

Board Practical Programs

The document contains a series of Python programming tasks involving the creation and manipulation of arrays and DataFrames using the NumPy and pandas libraries. It includes examples of creating rank 1 and rank 2 arrays, creating DataFrames from lists and dictionaries, adding new columns and rows, and checking for missing values. Additionally, it covers converting CSV files to DataFrames.
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)
2 views2 pages

Board Practical Programs

The document contains a series of Python programming tasks involving the creation and manipulation of arrays and DataFrames using the NumPy and pandas libraries. It includes examples of creating rank 1 and rank 2 arrays, creating DataFrames from lists and dictionaries, adding new columns and rows, and checking for missing values. Additionally, it covers converting CSV files to DataFrames.
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. To Write a python program for create an array of Rank 1, Rank 2 using 4.

4. Write a python program to create a DataFrame from NumPy arrays


numpy library. import pandas as pd
import numpy as np import numpy as np
arr1 = [Link]([1, 2, 3]) array1=[Link]([90,100,110,120])
print("Array with Rank 1:", arr1) array2=[Link]([50,60,70])
arr2 = [Link]([[1, 2, 3], [4, 5, 6]]) array3=[Link]([10,20,30,40])
print("Array with Rank 2:", arr2) marksDF = [Link]([array1, array2, array3], columns=[ 'A','B',
OUTPUT: 'C', 'D'])
Array with Rank 1: [1 2 3]
print(marksDF)
Output:
Array with Rank 2: [[1 2 3]
A B C D
[4 5 6]]
0 90.0 100.0 110.0 120.0
2. To Write a python program to create series using pandas for the 1 50.0 60.0 70.0 NaN
following data 2 10.0 20.0 30.0 40.0
3 Kavi
5 Shyam 5. Write a Python Code to add a new column for another student as given
1 Ravi below:
import pandas as pd
series1 = [Link](['Kavi', 'Shyam', 'Ravi'], index=[3, 5, 1])
print(series1)

3. Write a Python Code to create DataFrame from a list/dictionary using


the following data
Name Age City import pandas as pd
0 Alice 25.0 Delhi ResultSheet = {
1 Bob 30.0 Mumbai 'Rajat': [Link]([90, 91, 97], index=['Maths', 'Science', 'Hindi']),
2 Charlie 35.0 Chennai 'Amrita': [Link]([92, 81, 96], index=['Maths', 'Science', 'Hindi']),
3 David NaN Kolkata 'Meenakshi': [Link]([89, 91, 88], index=['Maths', 'Science', 'Hindi']),
4 Eva 28.0 Bangalore 'Rose': [Link]([81, 71, 67], index=['Maths', 'Science', 'Hindi']),
import pandas as pd 'Karthika': [Link]([94, 95, 99], index=['Maths', 'Science', 'Hindi'])
data = { }
'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eva'], Result = [Link](ResultSheet)
'Age': [25, 30, 35, None, 28], print("Initial Result DataFrame:\n")
'City': ['Delhi', 'Mumbai', 'Chennai', 'Kolkata','Bangalore'] print(Result)
}
df = [Link](data) # i. Add new column for Fathima
print(df) Result['Fathima'] = [89, 78, 76]
print("\nAfter Adding Column for Fathima:\n")
print(Result)
ResultSheet={'Maths': [Link]([90,91,97,89,65,93],
b) Adding two New Row to a DataFrame as given below: index=['Heena','Shefali','Meera','Joseph','Suhana','Bismeet']),
'Science':[Link]([92,81,[Link],87,50,88],
[Link]['English'] = [90, 92, 89, 80, 90, 88] index=['Heena','Shefali','Meera','Joseph','Suhana','Bismeet']), 'English':
[Link]['AI'] = [96, 98, 99, 90, 95, 97] [Link]([89, 91, 88,78,77,82],
print("\nAfter Adding Rows 'English' and 'AI':\n") index=['Heena','Shefali','Meera','Joseph','Suhana','Bismeet']), 'Hindi':
print(Result) [Link]([81, 71, 67,82,[Link],89],
index=['Heena','Shefali','Meera','Joseph','Suhana','Bismeet']), 'AI':
[Link]([94, 95, 99,[Link],96,99],
6. To Write a Python program to create a dataframe index=['Heena','Shefali','Meera','Joseph','Suhana','Bismeet'])}
i. To Display the Data frame marks = [Link](ResultSheet)
import pandas as pd print(marks)
data = {
'Name': ['Arnav', 'Neha', 'Priya', 'Rahul'], b. Write the command to check for missing values (NaNs) in the
'Marks': [85, 92, None, 83], entire DataFrame.
'Sports': ['Cricket', 'Volleyball', 'Hockey', None] #check for missing values
} print([Link]())
df = [Link](data) print(marks['Maths'].isnull().any())

# i. Display the DataFrame orange data mining


print("i. Full DataFrame:\n")
print(df)
ii) # Display the number of Missing Values
print("\niv. Number of Missing Values:\n")
print([Link]().sum())

7. Write a Python code to convert the csv to DataFrame.


import pandas as pd
df=pd.read_csv("[Link]")
print(df)

8. Write a Python program to create a DataFrame named marks using the


dictionary ResultSheet with student names as index and subjects as
columns.

import pandas as pd
import numpy as np

You might also like