Ip Project Work 2
Ip Project Work 2
1 Sunday
2 Monday
3 Tuesday
4 Wednesday
5 Thursday
(a)np arrays
(b)Dictionary
Input:
days =['Sunday','Monday','Tuesday','Wednesday','Thursday']
array = np.array(days)
print (s1)
(b)import pandas as pd
s2 = pd.Series (dict1)
print (s2)
Output
(a)
(b)
Practical Question – 2
PANDAS SERIES QUESTION - 2
A series that stores the average marks scored by 10 students is as follows –
[90, 89, 78, 91, 80, 88, 95, 98, 75, 97]
Write a Input: to :
(a)Create a series using the given dataset with index values (1-10)
generated using arange ( ).
(e) Update the mark averages of roll number (index) 5 to 82 and display the series.
(f) Display mark detail of roll number 7, 8 and 9.
Input:
import pandas as pd
import numpy as np
dataset = [90, 89, 78, 91, 80, 88, 95, 98, 75, 97]
(a)print(s1)
print (s1)
(c)print (s1.head(3))
(d) print(s1[s1<80])
(e) s1[5] = 82
print (s1)
(a)
(b)
(c)
(d)
(e)
(f)
Practical Question – 3
PANDAS SERIES QUESTION - 3
Write a program to store employees’ salary data of one year.
Salary_data = [120000, 120000, 130000, 115000, 300000, 150000, 100000, 250000, 160000,
400000, 250000, 350000]
Index = Jan, Feb, March, April, May, June, July, Aug, Sep, Oct, Nov, Dec
Input:
import pandas as pd
print (s1)
(c)s2 = s1 + (s1*0.1)
print (s2)
print (s1)
Output
(a)
(b)
(c)
(d)
Practical Question – 4
PANDAS SERIES QUESTION - 4
Create a Series as follows :
1 5 2 10 3 15 4 20 5 25
Input:
import pandas as pd
import numpy as np
a = np.arange(5, 26, 5)
print (s1)
print (s2)
(b)s3 = s1.drop(5)
print (s3)
Output
(i)
(b)
Practical Question – 5
DATAFRAME - CREATION
Study the following Data Frame representing quarterly sales data of 2017, 2018 and 2019 and
create the same using
(a)Dictionary of Series
(b)List of Dictionaries.
Input:
(a)import pandas as pd
print (df1)
(b)L = [{2017 : 400000, 2018 : 420000, 2019 : 430000},
'Qtr4'])
print (df2)
Output
(i)
(b)
Practical Question – 6
DATAFRAME – ADD AND REMOVE OPERATIONS
Create a Data Frame showing details of employees with Name, Department, Salary, and
Bonus amount. The employee Input: should be the indices of the Data Frame as shown.
(a)Create the data frame using dictionary of lists and display the same.
(d) Remove all details of E103 since he left the company. Display the
modified dataset.
Input:
print (df1)
print (df1)
print (df1)
Output
(a)
(b)
(c)
(d)
Practical Question – 7
DATAFRAME - ITERATIONS
Create a Data Frame as shown using list of dictionaries.
Input:
import pandas as pd
print (df1)
Input:
print (df1)
Output
Practical Question – 9
DATAFRAME – STATISTICAL FUNCTIONS
Create a Data Frame names ‘Cricket’ and perform all statistical functions on the same.
Input:
import pandas as pd
'Age' : [26, 25, 25, 24, 31], 'Score' : [87,67, 89, 55, 47]}
Create the above Data Frame and add the following information using append() function.
Add job information as follows: Engr, Engr, Dr, Dr, HR, Analyst, HR
Input:
import pandas as pd
df2 = df1.append({'Name' : 'Mike', 'Age' : 17, 'City' :'Las Vegas', 'Country' : 'US'},
ignore_index = True)
print (df3)
df3 ['Job'] = ['Engr', 'Engr', 'Dr', 'Dr', 'HR','Analyst', 'HR']
print (df3)
Output
Practical Question –11
DATAFRAME – REMOVAL OF ROWS AND COLUMNS
Consider the following Data Frame.
(d) Display Physics and Chemistry marks of Suman and Gayatri only.
Input:
import pandas as pd
data = {'Name' : ['Suman', 'Gayatri', 'Vishruti', 'Alpa','Hetal'],
'English' : [74, 79, 48, 53, 68], 'Physics' :[76, 78, 80, 76, 73],
'Chemistry' : [57, 74, 55, 89, 70],'Biology' : [76, 85, 63, 68, 59],
(i)
(b)
(c)
(d)
Practical Question –12
DATAFRAME – ACCESSING ROWS AND COLUMNS
Consider the given Data Frame :
Input:
import pandas as pd
print (df1['Eco'])
(i)
(b)
(c)
(d)
Practical Question –13
DATAFRAME – ACCESSING ELEMENTS USING OPERATIONS
Create the Data Frame shown :
(b)Select all cases where age is greater than 28 and grade is “A”
(c)Select the degree cell where age is greater than 28 and grade is “A”
(d) Display details of MBA and MS graduates
Input:
print(df1)
print(df1[df1['age']>28])
(i)
(b)
(c)
(d)
(e)
Practical Question –14
DATAFRAME – BOOLEAN INDEXING
Create a Data Frame containing online classes information as follows :
Input:
import pandas as pd
print (df1)
print (df1.loc[True])
print (df1.loc[False])
Output
(i)
(b)
Practical Question –15
CSV IMPORT AND EXPORT
Import the following data from the CSV File “PriceList”.
Increase the price of all items by 2% and export the updated data to another CSV File
“PriceList_Updated”.
Input:
import pandas as pd
df = pd.read_csv("PriceList.csv")
print (df)
df['Price'] = df['Price'] + (df['Price']*0.02)
print(df)
df.to_csv(r"PriceList_Updated.csv")
Output
Practical Question –16
DATA HANDLING USING CSV FILES
Create a menu driven program to perform the following:
(c)Delete details.
Input:
print ("1. Add Details\n2. Update Details\n3. Delete Details\n4. View all Details\n5. Display
Graph\n")
if choice == 1:
df = pd.DataFrame (columns = ['Roll No.', 'Name','Marks'])
print (df)
elif choice == 2 :
df = pd.read_csv(r"Stu.csv")
print (df)
elif choice == 3:
df = pd.read_csv("Stu.csv")
rn = int(input("Roll number : "))
df1 = df.drop(rn-1)
print (df1)
df1.to_csv(r"Stu.csv")
elif choice == 4:
df = pd.read_csv(r"Stu.csv")
print (df)
elif choice == 5:
df1= pd.read_csv(r"Stu.csv")
x = df1['Name'].values.tolist()
y = df1['Marks'].values.tolist()
plt.bar(x, y, width = 0.5)
Output
(i)
(b)
(c)
(d)
(e)
Practical Question –17
DATA VISUALISATION – LINE AND BAR CHARTS
Consider the data given below. Using the above data, plot the following:
Input:
(i)
plt.show()
(b)
plt.show()
(c)
a = np.arange(len(Apps))
plt.xticks(a, Apps)
plt.title ('Apps, Prices and its number of downloads')
(i)
(b)
(c)
Practical Question –18
DATA VISUALISATION – MULTILINE AND MULTIBAR CHARTS
Consider the data given below. Using the above data, plot the following:
(b)A multibar chart representing rainfall measurement for first quarter of year each of
North, South and central region.
Input:
(i)
import numpy as np
plt.xlabel ('Months')
plt.ylabel ('Rainfall (in mm)')
plt.show()
(b)
import numpy as np
import matplotlib.pyplot as plt
quarter=['Jan','Feb','Mar']
plt.grid (True)
plt.show()
Output
(i)
(b)
Practical Question –19
DATA VISUALISATION – SCHOOL RESULT ANALYSIS
Given the school result data. Analyze the performance of students using data visualization
techniques.
(a)Draw a bar chart to represent above data with appropriate labels and title.
(b)Given subject average data for 3 years. Draw a multi bar chart to
represent the above data with appropriate labels, title, and legend.
[90, 99, 95, 92, 92, 90, 85, 82, 75, 78, 83, 82, 85, 90, 92, 98, 99, 100]
Input:
(i)
plt.grid (True)
plt.show()
(b)
import matplotlib.pyplot as plt; import numpy as np
plt.grid (True)
plt.show()
(c)
plt.xlabel('Marks')
plt.ylabel ('Frequency')
plt.show()
Output
(i)
(b)
(c)
Practical Question – 20
COVID DATA ANALYSIS
Export the CSV File “CovidData.csv” and plot a bar chart with Country vs. Total Confirmed
cases.
Input:
import pandas as pd
country = df['Country'].tolist()
plt.xlabel ('Country')
plt.show()
Output
Practical Question – 21
COMPANY SALES DATA ANALYSIS
Export the CSV File “CompanySalesData.csv” and plot a line chart with month number
against total profit.
Input:
import pandas as pd
x = df['month_num'].tolist()
y = df['total_profit'].tolist()
mfc ='midnightblue')
plt.xlabel ('Month Number')
plt.ylabel('Total_profit')
plt.show()
Output