0% found this document useful (0 votes)
1K views14 pages

Dataframe Practical

The document describes 6 programming problems involving creating and manipulating Pandas DataFrames. The problems include sorting DataFrames by columns, calculating total and average marks for students, displaying subsets of rows and columns, adding and removing columns/rows, and joining DataFrames. Sample datasets with student exam scores and employee data are provided.

Uploaded by

subash murugaiya
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)
1K views14 pages

Dataframe Practical

The document describes 6 programming problems involving creating and manipulating Pandas DataFrames. The problems include sorting DataFrames by columns, calculating total and average marks for students, displaying subsets of rows and columns, adding and removing columns/rows, and joining DataFrames. Sample datasets with student exam scores and employee data are provided.

Uploaded by

subash murugaiya
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/ 14

PRACTICAL -5

PANDAS DATAFRAME

DATAFRAME -PROGRAM-1
5. Write a program in Python to create a DataFrame DF as shown below
and perform the following operations on it.

RNO NAME ENG PHY ECO INFO MATHS


1 ANN 60 89 90 80 80
2 TOM 70 67.5 78.5 86.5 89.5
3 MARY 55 55.75 69.25 56 76.25
4 SMITH 80 60.5 40 73 60.5
5 BLAKE 75 56.25 67.5 85.25 40.5

a) Sort the table in alphabetical order of name.


b) Sort the table in descending order of MATHS marks.
c) Sort the table first by decreasing order of RNO and ascending order of
NAME.
d) Descending order of MATHS and ascending order of INFO marks.
e) To get the total marks for each student.
f) To get the average marks for each student.

PROGRAM:
OUTPUT:
PRACTICAL- 6
PANDAS DATAFRAME
DATA FRAME -PROGRAM-2
6. Write a program in Python to create a DataFrame DF as shown below
and perform the following operations on it.

NO NAME AGE DEPT DOJ SALARY


1 JUGAL 34 COMPUTER 1994-01-10 10000
2 SHARMILA 31 HISTORY 1998-03-24 12000
3 SANDEEP 32 MATHS 1996-12-12 20000
4 SANGEETHA 35 HISTORY 1999-07-01 15000
5 RAKESH 42 COMPUTER 1998-06-27 16000

a) To display the first three rows of the DataFrame.


b) To display the last 4 rows of the DataFrame
c) To add a new column gender to the above table.
d) To add a new row to the above Dataframe.
e) To display the row labels and column labels of the above DataFrame,
f) To display the datatype of the each column and display the
dimension of the above DataFrame.
g) To display the total number of elements in the above dataframe.
h) To display the column age and its maximum value from the above
DataFrame.
i) To display the column salary and its maximum value from the above
DataFrame.
j) To remove the column gender from the above DataFrame.
k) To remove the 5th row of the above DataFrame.
PROGRAM:

\
OUTPUT:
PRACTICAL -7
PANDAS DATA FRAMES
DATA FRAMES-PROGRAM-3

7) Create the following DataFrame Sales containing year wise sales


figures for five sales persons in INR. Use the years as column labels,
and sales person names as row labels.

2017 2018 2019 2020


ANN 100.5 12000 20000 50000
SHRUTI 150.8 18000 50000 60000
RAJ 200.9 22000 70000 70000
ANKIT 300 30000 100000 80000
JUGAL 400 45000 125000 90000

a) Display the dimensions, shape, size and values of Sales.


b) Display the first 2 columns of Sales.
c) Display the last 3 rows of Sales without using tail function.
d) Display the sales made by all salespersons in the year 2020.
e) Display the sales made by ANN and RAJ in the year 2017 and
2018.
f) Display the sales made by SHRUTI in 2018.
g) Update the sale made by ANKIT in 2018 to 85000.
h) Delete the data for the year 2019 from the DataFrame Sales.
i) Delete the data for sales man JUGAL from the DataFrame Sales.
j) Change the DataFrame Sales such that it becomes its transpose.
PROGRAM:
OUTPUT:
PRACTICAL-8
PANDAS DATA FRAME

DATA FRAMES-PROGRAM-4

8) a) Write a Pandas program to join the two given data frames along
rows and assign all data. Data Frames are converted from
dictionaries Dic1 and Dic2 with the keys as name, perc and qualify
with values.

Dic1={‘name’:[‘Aman’, ‘Kamal’, ‘Amjad’, ‘Rohan’, ‘Amit’, ’Sumit’,


‘Matthew’, ‘Karthik’, ‘Pooja’], ‘perc’:[79.5,29,90.5, np.nan , 32, 65,
56, np.nan, 29, 89 ], ‘qualify’:[‘yes’, ‘no’, ‘yes’, ‘no’, ‘no’, ‘yes’, ‘yes’,
‘no’, ‘no’, ‘yes’]}
Dic2= {‘name’: [‘Parveen’, ‘Ahil’, ‘Ashaz’, ‘Shifin’, ‘Hanash’],
‘perc’: [89.5,92,90.5,91.5,90], ‘qualify’: [‘yes’, ‘yes’, ‘yes’, ‘yes’,
‘yes’]}

PROGRAM:
OUTPUT:
8) b) Write a Pandas program to join the two given data frames along
columns and assign all data. Data Frames are converted from
dictionaries Dic1 and Dic2 with the keys name, perc and qualify with
values

Dic1= {‘name’: [‘Aman’, ‘Kamal’, ‘Amjad’, ‘Rohan’, ‘Amit’, ‘Sumit’,


‘Matthew’, ‘Kartik’, ‘Kavita’, ‘Pooja’], ‘perc’: [79.5, 29, 90.5, np.nan,
32, 65, 56, np.nan, 29, 89], ‘qualify’: [‘yes’, ‘no’, ‘yes’, ‘no’, ‘no’, ‘yes’,
‘yes’, ‘yes’, ‘no’, ‘no’, ‘yes’]}

Dic2= {‘name’: [‘Parveen’, ‘Ahil’, ‘Ashaz’, ‘Sherin’, ‘Hibah’], ‘perc’:


[89.5, 92, 90.5, 91.5, 90], ‘qualify’: [‘yes’, ‘yes’, ‘yes’, ‘yes’, ‘yes’]}

PROGRAM:
OUTPUT:

You might also like