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

Advance Operations On Dataframes

The document outlines tasks to practice working with dataframes in Python including creating dataframes with sample data, finding totals and averages by columns, and sorting dataframes by different columns. It provides two examples of dataframes to work with for tasks like finding totals by employee and state, sorting by score or multiple columns, and sorting using or not using the index.

Uploaded by

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

Advance Operations On Dataframes

The document outlines tasks to practice working with dataframes in Python including creating dataframes with sample data, finding totals and averages by columns, and sorting dataframes by different columns. It provides two examples of dataframes to work with for tasks like finding totals by employee and state, sorting by score or multiple columns, and sorting using or not using the index.

Uploaded by

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

ADVANCE OPERATIONS ON DATAFRAMES

Task-1 (Done in class today) To do again and send


Python Program to create the dataframe with following Values
Name of Sales Quarter State
Employee
Mohak 1000 1 Rajasthan
Vijay 300 1 Punjab
Tapsi 400 1 Gujrat
Mansi 500 2 Goa
Vijay 800 2 Punjab

Task-2
Find total sales by Employee in above dataframe
Task-3
Find total sales by state in above dataframe
Task-4
Find total sales by both employee& state in above dataframe
Task-5
Find Max individual sale by State in above dataframe
Task-6
Find Mean, median and min sales by State in above
dataframe
EXAMPLE -2 (To be done as Homework)
Task-1
Python Program to create the dataframe with following
Values
Name Year Score Catches
Mohak 2012 10 2
Rajesh 2012 22 2
Freya 2013 11 3
Aditya 2014 32 3
Anika 2014 23 3

Task-2 example how to send the document


Sort the dataframe’s rows by score, in descending order
import pandas as pd
data = {'name': ['Mohak', 'Rajesh', 'Freya', 'Aditya', 'Anika'],
'year': [2012, 2012, 2013, 2014, 2014],
'score': [10, 22, 11, 32, 23],
'catches': [2, 2, 3, 3, 3]}
df = pd.DataFrame(data, columns= ['name', 'year','score','catches'])
print(df)
r=df.sort_values(by='score', ascending=False)
print(r)
OUTPUT
name year score catches
3 Aditya 2014 32 3
4 Anika 2014 23 3
1 Rajesh 2012 22 2
2 Freya 2013 11 3
0 Mohak 2012 10 2
Task-3
Sort the dataframe’s rows by catches and then by score, in
ascending order/sort by multiple columns
Task-4
Sort the dataframe’s rows using index
Task-5
Sort the dataframe’s rows descending of index value

You might also like