Example Programs
Example Programs
Write a Pandas program to select the rows where the number of attempts in the
examination is greater than 2.
Sample Python dictionary data and list labels:
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael',
'Matthew', 'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, 17.6, 9, 20, 14.5, 18.6, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']}
2. Write a Pandas program to replace all the NaN values with mean in a column of a
dataframe.
3. Write a python program to create data frame using with the name Employee with titles as
Empid, Empname, Empdesig. Insert 10 records into it and display them. Add the title
Empcontact as a new title and display the results.
4. With a given tuple (1,2,3,4,5,6,7,8,9,10), write a program to print the first half values in
one line and the last half values in one line.
5. Write a program to read the information present in a welcome1.txt file such as student
name, roll no and also append the information such as contact address, parent details, and
city zip code and display it.
6. Write a program to count the vowels, consents, digits, and special symbols present in a
file.
7. Write a program to copy the information present in one file to another file.
8. Write a python program to check whether a given no is prime no or not using functions.
9. Program to get the difference between the two tuples.
10. Given list of tuples, remove all the tuples with length K. Input : test_list = [(4, 5), (4, ),
(8, 6, 7), (1, ), (3, 4, 6, 7)], K = 2 Output : [(4, ), (8, 6, 7), (1, ), (3, 4, 6, 7)] Explanation :
(4, 5) of len = 2 is removed.
11. Program to generate and print a dictionary that contains a number (between 1 and n) in
the form (x, x*x). Sample Input: (n=5) : Expected Output : {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
12. Given an integer tuple, for each element in the tuple check whether there exists a
smaller element on the next immediate position of the array. If it exists print the smaller
element. If there is no smaller element on the immediate next to the element then print -1.
Example Input: 4 2 1 5 3 Output: 2 1 -1 3 -1
13. Python Program to Generate Random Numbers from 1 to 20 and Append Them to the
List.
14. Write a program to explore all 11 attributes of series in pandas.
15. Write a pandas program to display employee details whose salary is >25000 and <50000,
from employee dataset and also display employee names contains character ‘s’ using
compound condition.
16. Write a pandas program to apply conditional changes on employee dataset using salary
column on designation column. (Based on salaries of the employees create a new column
and assign designations to them)