0% found this document useful (0 votes)
50 views23 pages

IP Lab Record

Ip lab record

Uploaded by

RAZER GAMING
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)
50 views23 pages

IP Lab Record

Ip lab record

Uploaded by

RAZER GAMING
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/ 23

Date: PROGRAM NO:-1

AIM:-

To write a python program to create the panda’s series from a dictionary of values and an ndarray.

PROGRAM:-

Create series from ndarray

import pandas as pd
import numpy as np
s=pd.Series(np.array([1,2,3,4,7,8,9]))
print(s)

Create series from Dictionary

import pandas as pd
dictionary={‘A’:10,’B’:20,’C’:30}
s=pd.Series(dictionary)
print(s)

ndarray
Output:-

0 1
1 2
2 3
3 4
4 7
5 8
6 9

Dictionary
Output:-

A 10
B 20
C 30

RESULT:-
The program for creating a panda’s series from a dictionary of values and an ndarray was
successfully executed.
Date: PROGRAM NO:-2

AIM:-

To write a python program to print all the elements that are above the 75th percentile from given series.

PROGRAM:-

import pandas as pd
import numpy as np
s=pd.Series(np.array([1,3,4,7,8,8,9]))
print(s)
res=s.quantile(q=0.75)
print()
print('75th Percentile of the series is:::')
print(res)
print()
print('The elements that are above the 75th Percentile::')
print(s[s>res])

OutPut:

0 1
1 3
2 4
3 7
4 8
5 8
6 9
dtype: int64
75th Percentile of the series is:::
8.0
The elements that are above the 75th Percentile::
6 9
dtype: int64

RESULT:-
The program for print all the elements that are above the 75th percentile from given series was successfully
executed.
Date: PROGRAM NO:-3

AIM:-

To write a python program to Create a Data Frame quarterly sales where each row contains the item category, item
name, and expenditure. Group the rows by the category and print the total expenditure per category.

PROGRAM:-

import pandas as pd
dic={'itemcat':['car','AC','Aircooler','Washing Machine'],
'itemname':['Ford','Hitachi','Symphony','LG'],'expenditure':[7000000,50000,12000,14000]}
quartsales=pd.DataFrame(dic)
print(quartsales)
qs=quartsales.groupby('itemcat')
print('Result after Filtering DataFrame')
print(qs['itemcat','expenditure'].sum())

OutPut:

RESULT:-
The program to Create a Data Frame quarterly sales where each row contains the item category, item name, and
expenditure. Group the rows by the category and print the total expenditure per category was successfully
executed.
Date: PROGRAM NO:-4

AIM:-

To write a python program to create a data frame for examination result and display row labels, column labels data
types of each column and the dimensions

PROGRAM:-

import pandas as pd
dic={'Class':['I','II','III','IV','V','VI','VII','VIII','IX','X','XI','XII'],'Pass-
Percentage':[100,100,100,100,100,100,100,100,100,98.6,100,99]}
result=pd.DataFrame(dic)
print(result)
print(result.dtypes)
print('shape of the dataframe is::::')
print(result.shape)

OutPut:
Class Pass-Percentage
0 I 100.0
1 II 100.0
2 III 100.0
3 IV 100.0
4 V 100.0
5 VI 100.0
6 VII 100.0
7 VIII 100.0
8 IX 100.0
9 X 98.6
10 XI 100.0
11 XII 99.0
Class object
Pass-Percentage float64
dtype: object
shape of the dataframe is::::
(12, 2)

RESULT:-
The program Create a data frame for examination result and display row labels, column labels data types of each
column and the dimensions was successfully executed.
Date: PROGRAM NO:-5

AIM:-

To write a python program for Filtering out rows based on different criteria such as duplicate rows.

PROGRAM:-

import pandas as pd
dic={'Name':['Rohit','Mohit','Deepak','Rohit','Deepak','Sohit','Geeta'],'MarksinIP':[85,45,92
,85,92,96,84]}
marks=pd.DataFrame(dic)
duplicateRow=marks[marks.duplicated(keep=False)]
print(duplicateRow)

OutPut:
Name MarksinIP
0 Rohit 85
2 Deepak 92
3 Rohit 85
4 Deepak 92

RESULT:

The program for Filtering out rows based on different criteria such as duplicate rows was successfully
executed.
Date: PROGRAM NO:-6

AIM:-

To write a python program for creating a data frame based on ecommerce data and generate descriptive statistics
(Mean, Median, Mode, Quartile and Variance)

PROGRAM:-

import pandas as pd
sales={'InvoiceNo':[1001,1002,1003,1004,1005,1006,1007],'ProductName':['LED','AC','Deodrant',
'Jeans','Books','Shoes','Jackets'],'Quantity':[2,1,2,1,2,1,1],'Price':[65000,55000,500,2500,9
50,3000,2200]}
df=pd.DataFrame(sales)
print(df['Price'].describe().round(2))

OutPut:

RESULT:

The program for creating a data frame based on ecommerce data and generate descriptive statistics (Mean,
Median, Mode, Quartile and Variance) was successfully executed.
Date: PROGRAM NO:-7

AIM:-

To write a python program for finding the sum of each column or to find the column with lowest mean.

PROGRAM:-

import pandas as pd
Profit={'TCS':{'Qtr1':2500,'Qtr2':2000,'Qtr3':3000,'Qtr4':2000},'WIPRO':{'Qtr1':2800,'Qtr2':2
400,'Qtr3':3600,'Qtr4':2400'},
'L&T':{'Qtr1':2100,'Qtr2':5700,'Qtr3':35000,'Qtr4':2100}}
df=pd.DataFrame(Profit)
print(df)
print()
print('Column wise sum in dataframe is:::')
print(df.sum(axis=0))
print()
print('Column wise mean value are:::::::::')
print(df.mean(axis=0))
print()
print('Column with minimum mean value is ::::::::::::')
df.mean(axis=0).idxmin()

OutPut:
Date: PROGRAM NO:-8

AIM:-

To write a python program to replace all negative values in a data frame with a 0.

PROGRAM:-

import pandas as pd
dic={'Data1':[-5,-2,5,8,9,-6],
'Data2':[2,4,10,15,-5,-8]}
df=pd.DataFrame(dic)
print(df)
print()
print("dataFrame after replacing negative values with 0:::")
df[df<0]=0
print(df)

OutPut:

RESULT:

The program to replace all negative values in a data frame with a 0 was successfully executed.
Date: PROGRAM NO:-9

AIM:-

To write a python program to replace all missing values in a data frame with a 999.

PROGRAM:-

import pandas as pd
import numpy as np
empdata={'empid':[101,102,103,104,105,106],
'ename':['Sachin','Vinod','Lakhbir',np.nan,'Devinder','UmaSelvi'],
'Doj':['12-01-2012','15-01-2007','05-09-2007','17-01-2012',np.nan,'16-01-2012']}
df=pd.DataFrame(empdata)
print(df)
df=df.fillna({'ename':999,'Doj':999})
print()
print(df)

OutPut:

RESULT:

The program to replace all missing values in a data frame with a 999 was successfully executed.
Date: PROGRAM NO:-10

AIM:-

To write a python program for importing and exporting pandas and CSV files.

PROGRAM:-

Importing data between pandas and csv file

import pandas as pd
df=pd.read_csv('emp.csv')
print(df)

Exporting data between pandas and csv file

import pandas as pd
l=[{'Name':'Sachin','SirName':'Tendulkar'},
{'Name':'MahendraSingh','SirName':'Dhoni'}]
df1=pd.DataFrame(l)
df1.to_csv(r'C:\Users\Arcade\Desktop\empdata.csv',index=False, header=True)
print(df1)

OutPut:

Importing data between pandas and csv file

Exporting data between pandas and csv file


empdata.csv

RESULT:-
The program for importing and exporting pandas and CSV files was successfully executed.
Date: PROGRAM NO:-11

AIM:-

To write a python program for analyzing the performance of the students on different parameters with given
school result data e.g subject wise or class wise.

PROGRAM:-

import matplotlib.pyplot as plt


Subject=['Physics','Chemistry','Hindi','Biology','Computer Science']
Percentage=[85,78,65,90,100]
plt.bar(Subject, Percentage, align='center', color='red')
plt.xlabel('Subject Name')
plt.ylabel('Pass Percentage')
plt.title('Bar Graph for Result Analysis')
plt.show()

output

RESULT:-
The program for analyzing the performance of the students on different parameters with given school result data
was successfully executed.
Date: PROGRAM NO:-12

AIM:-

To write a python program to analyze and plot appropriate charts with title and legend for the data frames.

PROGRAM:-

import matplotlib.pyplot as plt


import numpy as np
S=['1st','2nd','3rd']
per_Sc=[95,89,77]
per_Com=[90,93,75]
per_Hum=[97,92,77]
x=np.arange(len(S))
plt.bar(x,per_Sc,label='Science',width=0.25,color='green')
plt.bar(x+.25,per_Com,label='Commerce',width=0.25,color='red')
plt.bar(x+.50,per_Hum,label='Humanities',width=0.25, color='gold')
plt.xticks(x,S)
plt.xlabel('Position')
plt.ylabel('Percentage')
plt.title('Bar Graph for Result Analysis')
plt.legend()
plt.show()

output
RESULT:-
The program to analyze and plot appropriate charts with title and legend for the data frames was successfully
executed.
Date: PROGRAM NO:-13

AIM:-

To write a python program to take data of your interest from an open source (e.g. data.gov.in), aggregate and
summarize it.Then plot it using different plotting functions of matplotlib.

PROGRAM:-

CSV File

import pandas as pd
import matplotlib.pyplot as plt
df=pd.read_csv(“Census.CSV”)
print(df)

import pandas as pd
import matplotlib.pyplot as plt
df-=pd.read_csv(“census.CSV”)
slices=(df[‘Total Population of other’].head(6))
states=(df[‘State/UT’].head(6))
cols=['m', 'c', 'g', 'b', 'r', 'gold']
exp=[0,0,0,0,0,0.1]
plt.pie(slices,labels=states,colors=cols,startangle=90,explode=exp,shadow=True,autopct=’%.1f%
%’)
plt.title(‘2011 Census Data’)
plt.legend()
plt.show()
Output

RESULT:-
The program to take data of your interest from an open source (e.g. data.gov.in), aggregate and summarize it.Then
plot it using different plotting functions of matplotlib was successfully executed.
Date: PROGRAM NO:-14

AIM:-

To write a SQL commands for Student table.

PROGRAM:-

1. Create a student table with the student id, name, and marks as attributes where the student id is the primary
Key.

2. Insert the details of a new student in the above table.

3. Delete the details of a student in the above table.


4. Use the select command to get the details of the students with marks more than 80.

5. Find the min, max, sum, and average of the marks in a student marks table.

6. Write a SQL query to order the (student ID, marks) table in descending order of the marks.

Output 2.

Output 3
4.

Output 5

6.
RESULT:-

The program using SQL commands for the table Student was successfully executed.
Date: PROGRAM NO:-15

AIM:-

To write a SQL commands for Customer table.

PROGRAM:-

1. Create a customer table with the CustomerID,customername, and country attributes where the CustomerID is the
primary Key.
Create table cust(customerID int primary key NOT NULL, customername char(20),country
char(20));

2. Insert the details of a new customer in the above table cust.

insert into cust values(101,’Vikram’,’India’);


insert into cust values(102,’Anand’,’UAE’);
insert into cust values(103,’Ayesha’,’KSA’);
insert into cust values(104,’Mathew’,’Canada’);
insert into cust values(105,’Ram’,’India’);
insert into cust values(106,’Sita’,’India’);

3. Find the total number of customers from each country in the table (customer ID, customer Name, country) using
group by.

select country,count(*) from cust group by country;

output 2.
Output 3

RESULT:-

The program using SQL commands for the table Customer was successfully executed.

You might also like