Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
5 views8 pages

Practical File Programs

The document contains a series of practical programming examples using Python's pandas and matplotlib libraries. It demonstrates how to create and manipulate data structures like Series and DataFrames, perform operations on them, and visualize data through plots. Each example includes input code and the corresponding output, covering various data handling techniques.

Uploaded by

ashsprings22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views8 pages

Practical File Programs

The document contains a series of practical programming examples using Python's pandas and matplotlib libraries. It demonstrates how to create and manipulate data structures like Series and DataFrames, perform operations on them, and visualize data through plots. Each example includes input code and the corresponding output, covering various data handling techniques.

Uploaded by

ashsprings22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

PRACTICAL FILE PROGRAMS

1. Input:
import pandas as pd
i = ['a', 'b', 'c', 'd']
v = [10, 20, 30, 40]
s = pd.Series(data=v, index=i)
print("The Series is:")
print(s)

Output:
The Series is:
a 10
b 20
c 30
d 40
dtype: int64

2. Input:
import numpy as np
import pandas as pd
arr = np.array([1, 2, 3, 4, 5])
squared_arr = arr ** 2
ms = pd.Series(squared_arr)
print("Series created from NumPy:")
print(ms)

Output:
Series created from NumPy:
0 1
1 4
2 9
3 16
4 25
dtype: int64

3. Input:
import pandas as pd
names = ['Shruti', 'Renu', 'Rinku', 'Nidhi', 'Tinku', 'Vidooshi',
'Rohit']
marks = [80, 60, 89, 90, 78, 82, 99]
students_series = pd.Series(data=marks, index=names)
print("Complete Student Marks:")
print(students_series)
high_scorers = students_series[students_series > 85]
print("\nStudents who scored more than 85:")
print(high_scorers)

Output:
Complete Student Marks:
Shruti 80
Renu 60
Rinku 89
Nidhi 90
Tinku 78
Vidooshi 82
Rohit 99
dtype: int64

Students who scored more than 85:


Rinku 89
Nidhi 90
Rohit 99
dtype: int64

4. Input:
import pandas as pd
percentages = pd.Series(data=[85, 78, 92, 67], index=['Aryan',
'Riya', 'Neha', 'Kabir'])
ages = pd.Series(data=[17, 16, 17, 18], index=['Aryan', 'Riya',
'Neha', 'Kabir'])
student_df = pd.DataFrame({'Percentage': percentages, 'Age':
ages})
print("Student Data Frame:")
print(student_df)
Student Data Frame:
Percentage Age
Aryan 85 17
Riya 78 16
Neha 92 17
Kabir 67 18

5. Input:
import pandas as pd
ratings = pd.Series([8.6, 7.4, 9.0], index=['Inception', 'Avatar',
'The Dark Knight'])
release_years = pd.Series([2010, 2009, 2008],
index=['Inception', 'Avatar', 'The Dark Knight'])
movies_dict = {'IMDB Rating': ratings, 'Release Year':
release_years}
movies_df = pd.DataFrame(movies_dict)
print("Movie Information Data Frame:")
print(movies_df)

Output:
Movie Information Data Frame:
IMDB Rating Release Year
Inception 8.6 2010
Avatar 7.4 2009
The Dark Knight 9.0 2008

6. Input:
import pandas as pd
df1 = pd.DataFrame({'Product ID': [101, 102, 103], 'Product
Name': ['Notebook', 'Pen', 'Backpack']})
df2 = pd.DataFrame({'Price': [120, 15, 900], 'In Stock': [True,
True, False]})
result_df = pd.concat([df1, df2], axis=1)
print("Concatenated DataFrame (along columns):")
print(result_df)

Output:
Concatenated DataFrame (along columns):
Product ID Product Name Price In Stock
0 101 Notebook 120 True
1 102 Pen 15 True
2 103 Backpack 900 False
7. Input:
import pandas as pd
df = pd.read_csv('Employee.csv')
print("First 5 records from Employee.csv:")
print(df.head())

Output:
First 5 records from Employee.csv:
Empid Name Age City Salary
0 100 Ritesh 25 Mumbai 15000.0
1 101 Akash 26 Goa 16000.0
2 102 Mahima 27 Hyderabad 20000.0
3 103 Lakshay 23 Delhi 18000.0
4 104 Meenu 25 Mumbai 25000.0

8. Input:

import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('Weatherdata.csv')

plt.plot(df['Week1'], color='red', label='Week 1')


plt.plot(df['Week2'], color='blue', label='Week 2')
plt.plot(df['Week 3'], color='green', label='Week 3')

plt.title("Weather Report")
plt.xlabel("Days")
plt.ylabel("Temperature in degree Celsius")
plt.legend()
plt.show()

9. Input:

import matplotlib.pyplot as plt

marks = [50, 50, 50, 65, 65, 75, 75, 80, 80, 90, 90, 90, 90]
no_of_stu = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

plt.plot(no_of_stu, marks, color='purple', marker='o',


linestyle='-')
plt.title("Marks Frequency Chart")
plt.xlabel("Number of Students")
plt.ylabel("Marks")
plt.grid(True)
plt.show()

10. Input:

import matplotlib.pyplot as plt

years = ['2015', '2016', '2017', '2018']


pass_percentages = [83, 85, 87, 90]

plt.bar(years, pass_percentages, color='mediumseagreen')


plt.title("CBSE Pass Percentage (2015–2018)")
plt.xlabel("Year")
plt.ylabel("Pass Percentage")

plt.ylim(0, 100)
plt.grid(axis='y', linestyle='--', alpha=0.6)
plt.show()

You might also like