0% found this document useful (0 votes)
188 views

Practical List

1. The document discusses creating and manipulating pandas Series and DataFrames. It includes examples of creating Series from various data types, indexing and slicing Series, and using head() and tail() functions on Series. 2. Topics on DataFrames include creating DataFrames from dictionaries, lists, text files, and CSV files. Examples are given for selecting rows and columns, adding/deleting rows and columns, and renaming rows and columns. 3. The document also discusses operations on DataFrames like indexing, boolean indexing, exporting to CSV, and data visualization using plots, histograms, and MySQL functions.

Uploaded by

Harsh Shah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
188 views

Practical List

1. The document discusses creating and manipulating pandas Series and DataFrames. It includes examples of creating Series from various data types, indexing and slicing Series, and using head() and tail() functions on Series. 2. Topics on DataFrames include creating DataFrames from dictionaries, lists, text files, and CSV files. Examples are given for selecting rows and columns, adding/deleting rows and columns, and renaming rows and columns. 3. The document also discusses operations on DataFrames like indexing, boolean indexing, exporting to CSV, and data visualization using plots, histograms, and MySQL functions.

Uploaded by

Harsh Shah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

12-Prac cal

1. Crea on of a Series

(a) Create a Series from an ndarray


Write a program to create a Series from an ndarray [100 200 500 67] with index cat,dog,lion, ger
Sample Output:
Cat 100
Dog 200
Lion 100
Tiger 67
dtype: int32
(b) Create a Series from a dic onary
Write a program to create a Series from a dic onary a ={"English":67, "Maths":78,"SST":56,"Science":89}
(c) Create a Series from a scalar value
Write a program to create a Series from a scalar value “xyz school” with index [0,1,2,3,4]
Sample Output
0 xyz School
1 xyz School
2 xyz School
3 xyz School
4 xyz School

(d) Create the Series from a Mathema cal Equa on


Consider the series [5 10 15 20]
Using a mathema cal equa on and create the Series [15 30 45 60] from it
2. Selec on Indexing and Slicing of Series

Fruits=['Apple','Orange','Banana','Cherries','Water Melon','Pear']
NoofFruitssold=[12,45,67,23,44,33]

Consider the two list given above create a Series from it and do the following
i. Display the no of oranges sold
ii. Display the Cherries,Water Melon and Pear using slicing
iii. Display Apple , Orange , Banana,Cherries using loc
iv. Display Banana , Cherries and Water Melon using iloc
Sample Output:
The no of oranges sold are: 45
Cherries , Water Melon and Pear
Cherries 23
Water Melon 44
Pear 33
dtype: int64
Apple , Orange , Banana,Cherries using loc
Apple 12
Orange 45
Banana 67
Cherries 23
dtype: int64
Banana , Cherries and Water Melon using iloc
Banana 67
Cherries 23
Water Melon 44
dtype: int64

3. Head() and Tail() func on in Series


Create a Series as given below using the head() func on print the first 5 rows and using the tail()
func on print the last three rows

peaches 20
oranges 33
cherries 52
pears 10
kiwi 12
Banana 56
Apple 45
dtype: int64

4. Creation of DataFrames

(a) Creation of DataFrames from dictionary of Series

data = {
'apples': [3, 2, 0, 1],
'oranges': [0, 3, 7, 2]
}
(b) Creation of DataFrames from list of dictionaries
data = [{'Apple': 10, 'Banana': 12},{'Apple': 5, 'Banana': 10, 'Custard Apple ': 20}]
Create a dataframe from the list of dictionaries given above

(c) Creation of DataFrames from Text file

Create a text file mydata.txt as follows and create a dataframe from it.

(d) Creation of DataFrames from csv file

Create a file in notepad as shown below and save it as myfile.csv and create a dataframe from it.

5. Display

Create a dataframe as given above and display the no of apples and oranges Lily has
Purchased

6. Iteration

Create a dataframe as shown below:


Total
Amit 34
Amman 56
Arman 77
Ayan 88
Aryan 38
Iterate through the dataframe and print the output as given below:
Row index: Amit value is Total 34
Name: Amit, dtype: int64
Row index: Amman value is Total 56
Name: Amman, dtype: int64
Row index: Arman value is Total 77
Name: Arman, dtype: int64
Row index: Ayan value is Total 88
Name: Ayan, dtype: int64
Row index: Aryan value is Total 38
Name: Aryan, dtype: int64

7. Iteration

Create a dataframe as given below Iterate through the dataframe and calculate the grades as per marks
(according to the criteria given below)
Marks Grade
M>=90 A+
M>=70 and M<90 A
M>=60 and Marks<70 B
M>=50 and Marks<60 C
M>=40 and Marks <50 D
M<40 F

Iterate through the dataframe and calculate the grade


8. Operations on rows and columns:

(a) (a) Add a row and a column

Create a dataframe as shown above


Add a row :- Mani – [14,34]
Add a column :- Strawberries :-[12,56,78,34,56]
(b) (c) Select a row and a column

From the database created above


i. Display the data of oranges
ii. Display the data of Riya

(d) (e) Delete a row or a column


From the database created above
i. Delete the data of oranges
ii. Delete the data of Riya

(f) (g) Rename the row or column

From the database created above


i. Rename the row index ‘Jai’ as “Jaison”
ii. Rename the column apples as ‘Apple’ ,’Strawberries’ as ‘Rasberry’

9. Operations on rows and columns:

Create a dataframe as given above .


i. Delete the column Computer Science using del
ii. Delete the column English using pop()
iii. Using the drop() delete the first record
10. Head and Tail functions

Create a dataframe as given above


i. Using head() display the first five records
ii. Using head() display the first two
iii. Using tail() display the last three
iv. Using tail() display the last five

11. Indexing using Labels

Consider the dataframe given above. Write the statement


i. to display the row with emp3( use the loc)
ii. to display the details of emp1 and emp3
iii. display the Profession of emp6

12. Boolean Indexing

Consider a dataframe as given below and write the statements with boolean indexing
Name English Maths
0 Manisha 90 95
1 Anil 32 69
2 Pravin 45 65
3 Shweta 97 55
4 Archana 95 95
5 Paritosh 56 78

i. Display with records with English marks greater than 90


ii. Display the records with Maths Marks less than 70
iii. Display the record with Maths and English mark greater than 90
iv. Display the record of the student who has got 90 or more in any subject.
13.

Create a dataframe as given above and write statements for the following
i. Display all the records with Red Colour
ii. Display all the records with the shape ‘Square’
iii. Display all the records with price more than 10

14. Expor ng Data to a csv file

Create a da rame as shown above and then save it as a csv file called student_data.csv

15. Impor ng data from a csv file

Create a csv file as given below using excel


Create a dataframe from the csv file

Data Visualization
16. Line plot

The table shows the daily earnings of a store for five days.

Day  Mo Tue We Thur Fri 


n  s  d  s 

Earnin 300  450  200  400  65


gs  0 

Write a program to Construct a line graph for the frequency table

17. Bar graph

Create a bargraph from the table given below.


18. Histogram
Below is the number of pages in each of the twenty books that Pedro read this summer.
584, 201, 255,44, 312, 334,234,456,333,341,444,123,555,456,664,721 67,444,555,555,   3613333

Using the data, Write a program to create a histogram.


19. Crea ng a Histogram from a dataframe

Create a dataframe df1 as shown below:

Plot a line graph using the dataframe


20. MySQL-Func ons text,numeric and date

WORKER_ID FIRST_NAME LAST_NAME SALARY JOINING_DATE DEPARTMENT

1 Monika Arora 100000 2014-02-20 HR


09:00:00
2 Niharika Verma 80000 2014-06-11 Admin
09:00:00
3 Vishal Singhal 300000 2014-02-20 HR
09:00:00
4 Amitabh Singh 500000 2014-02-20 Admin
09:00:00
5 Vivek Bha 500000 2014-06-11 Admin
09:00:00
6 Vipul Diwan 200000 2014-06-11 Account
09:00:00
7 Sa sh Kumar 75000 2014-01-20 Account
09:00:00
8 Gee ka Chauhan 90000 2014-04-11 Admin
09:00:00

1. Create the table Worker as given above

2. Write an SQL query to fetch “FIRST_NAME” from Worker table in upper case.

3. Write an SQL query to print the first three characters of FIRST_NAME from Worker table using substring.
4. Write an SQL query to find the posi on of the alphabet (‘a’) in the first name from Worker table.(only small
‘a’ )
5. Write an SQL query to find the posi on of the alphabet (‘A’) in the first name from Worker table.(only capital
‘A’ )
6. Write an SQL query to print the FIRST_NAME from Worker table a er removing white spaces from the right
side.
7. Write an SQL query to print the DEPARTMENT from Worker table a er removing white spaces from the le
side.
8. Write an SQL query that fetches the unique values of DEPARTMENT from Worker table and prints its length.

9. Write an SQL query to print details of the Workers whose FIRST_NAME contains ‘a’.(Using instr)

10. Write an SQL query to print details of the Workers who have joined in Feb’2014.(Using Year and
Month functions)
11. Write an SQL query to show only rows with odd Id from Worker table.
21. MySQL-Aggregate Functions

1. Write the Create table command to create the table Empl as shown above
2. Display the number of employees who belong to HR dept
3. Display the minimum Salary
4. Display the maximum Salary
5. Display the total Salary
22. MySQL-Querying and manipulating data using Group by, Having, Order by

Consider the Table Empl created in Q 21.

1. Display the name of dept and the total salary of each dept

2. Display month-wise minimum salaries

3. Display the dept and total salary of all depts. With total salary less than 100000

4. Display the records in alphabetical order of emp names

5. Display all the depts. And the minimum salary of the dept

You might also like