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

Assignment 2 - Jupyter Notebook

Uploaded by

Mahak
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)
93 views

Assignment 2 - Jupyter Notebook

Uploaded by

Mahak
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/ 8

Assignment 2 - Jupyter Notebook 22/04/24, 9:45 PM

In [6]: import matplotlib.pyplot as plt


import pandas as pd
import numpy as np

In [8]: Months=pd.date_range(start='2024-01',periods=12,freq='M')
Sales=[160, 220, 250, 230, 230, 240, 140, 260, 300, 280, 290, 400 ]
df = pd.DataFrame(Sales, index=Months, columns=['Sales'])
plt.figure(figsize=(12,6))
plt.plot(df.index,df['Sales'],marker='o',linestyle='-')
plt.title("MONTHLY SALES")
plt.xlabel("Months")
plt.ylabel("Sales")
plt.show()

http://localhost:8888/notebooks/Assignment%202.ipynb Page 1 of 9
Assignment 2 - Jupyter Notebook 22/04/24, 9:45 PM

In [10]: Age=[32, 55, 33, 34, 43, 52, 6, 60, 70, 65, 34, 32, 54, 26]
plt.boxplot(Age)
plt.show()

http://localhost:8888/notebooks/Assignment%202.ipynb Page 2 of 9
Assignment 2 - Jupyter Notebook 22/04/24, 9:45 PM

In [24]: salary=pd.read_csv("Salary.csv")
ax=salary.boxplot(column="salary",by="sex", figsize=(10,6))
ax.set(title="Group by sex",ylabel="salary")
plt.show()

http://localhost:8888/notebooks/Assignment%202.ipynb Page 3 of 9
Assignment 2 - Jupyter Notebook 22/04/24, 9:45 PM

In [16]:
dates = pd.date_range(start='2021-01-01', end='2021-12-31', freq='M')
sales_data = [100, 120, 130, 110, 105, 115, 125, 130, 135, 140, 145, 15
sales_df = pd.DataFrame({'Sales': sales_data}, index=dates)

monthly_sales = sales_df.resample('M').sum()

plt.figure(figsize=(10, 6))
plt.plot(monthly_sales.index, monthly_sales['Sales'], marker='o', lines
plt.title('Monthly Sales in 2021')
plt.xlabel('Month')
plt.ylabel('Sales')

plt.show()

http://localhost:8888/notebooks/Assignment%202.ipynb Page 4 of 9
Assignment 2 - Jupyter Notebook 22/04/24, 9:45 PM

In [31]:
data_dict = {
'name': ['s1', 's2', 's3', 's4', 's5', 's6'],
'age': [20, 20, 21, 20, 21, 20],
'math_marks': [100, 90, 91, 98, 92, 95],
'physics_marks': [90, 100, 91, 92, 98, 95],
'chem_marks': [93, 89, 99, 92, 94, 92]
}

df = pd.DataFrame(data_dict)
df.plot(kind='bar', x='name', y='chem_marks', color='blue')
plt.title('Bar Plot')
plt.xlabel('Name')
plt.ylabel('Chemistry Marks')
plt.show()

http://localhost:8888/notebooks/Assignment%202.ipynb Page 5 of 9
Assignment 2 - Jupyter Notebook 22/04/24, 9:45 PM

In [34]: data_dict = {
'name': ['s1', 's2', 's3', 's4', 's5', 's6'],
'age': [20, 20, 21, 20, 21, 20],
'math_marks': [100, 90, 91, 98, 92, 95],
'physics_marks': [90, 100, 91, 92, 98, 95],
'chem_marks': [93, 89, 99, 92, 94, 92]
}
df.head()
#plot data
df.plot(kind='line', color=['red', 'blue', 'brown', 'yellow']) # panda
plt.title= "Students marks",
plt.xlabel = "Students",
plt.ylabel= "Marks"
plt.show()

http://localhost:8888/notebooks/Assignment%202.ipynb Page 6 of 9
Assignment 2 - Jupyter Notebook 22/04/24, 9:45 PM

In [38]: data_dict = {
'name': ['s1', 's2', 's3', 's4', 's5', 's6'],
'age': [20, 20, 21, 20, 21, 20],
'math_marks': [100, 90, 91, 98, 92, 95],
'physics_marks': [90, 100, 91, 92, 98, 95],
'chem_marks': [93, 89, 99, 92, 94, 92]
}
df.head()
#plot data
df.plot(kind='scatter', x='name',y='age') # panda plot function
plt.title= "Students marks",
plt.xlabel = "Students",
plt.ylabel= "Marks"
plt.show()

21.01

- 20.8-

20.6-
8
20.4-

20.2-

20.0-
54
name

http://localhost:8888/notebooks/Assignment%202.ipynb Page 7 of 9
Assignment 2 - Jupyter Notebook 22/04/24, 9:45 PM

In [48]: data = {
'values': [1, 2, 3, 4, 5, 5, 5, 6, 6, 7, 8, 9, 10]
}

df = pd.DataFrame(data)
df["values"].plot(kind='hist', color='skyblue', edgecolor='black')
plt.title('Histogram of Values')
plt.xlabel('Value')
plt.ylabel('Frequency')

plt.show()

------------------------------------------------------------------
---------
TypeError Traceback (most recent c
all last)
Cell In[48], line 7
5 df = pd.DataFrame(data)
6 df["values"].plot(kind='hist', color='skyblue', edgecolor
='black')
----> 7 plt.title('Histogram of Values')
8 plt.xlabel('Value')
9 plt.ylabel('Frequency')

TypeError: 'tuple' object is not callable

3.0-

2.5-

2.0-

1.0-

0.5-

0.0
2 4 6 8 10

http://localhost:8888/notebooks/Assignment%202.ipynb Page 8 of 9

You might also like