Assignment - pandas

 Creating a DataFrame from a list of data and setting the index

import pandas as pd
#initialize a dataframe
df = pd.DataFrame(
[[21, 'Amol', 42, 67],
[23, 'Lini', 78, 69],
[32, 'Kiku', 74, 56],
[52, 'Ajit', 54, 76]],
columns=['rollno', 'name', 'physics', 'botony'])
print('DataFrame with default index\n', df)
#set column as index
df = df.set_index('rollno')
print('\nDataFrame with column as index\n',df)


Create a DataFrame from the dictionary of lists
import pandas as pd 
# dictionary of lists 
dict = {'name':["aparna", "pankaj", "sudhir", "Geeku"],
 'degree': ["MBA", "BCA", "M.Tech", "MBA"], 
'score':[90, 40, 80, 98]} 
# creating a dataframe from a dictionary 
df = pd.DataFrame(dict) 
print(df)

Learn to create DataFrames.In the first example given above do the following

1. Add 1 more row [30,'yourname',70,67]
2.print the students name is alphabetical order.
3.print the top 2 rows
4.print the bottom 2 rows
5.print the rollno, name and physics mark in the descending order of mark
6.Find the average mark in physics
7.Find the min and max marks in botony
8.Update the physics mark of the student Ajit to 80
9.print the number of rows and columns
10.print the column names
11.display the passed students in physics ( marks >=50)
12.Display the students passed in both the subjects.
13.write the DataFrame into a csv file
14.write the DataFrame into an excel file
15.plot name vs physics mark. scatter plot name vs botony mark.

Comments

Popular posts from this blog

Programming in Python CST 362 KTU CS Sixth Semester Elective Notes

Graphical User Interfaces ( GUI)

Turtle Graphics