-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq3.py
More file actions
58 lines (45 loc) · 1.66 KB
/
q3.py
File metadata and controls
58 lines (45 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#A3
import pandas as pd
import numpy as np
import statistics
import matplotlib.pyplot as plt
rf = pd.read_excel("Lab Session Data.xlsx", sheet_name="IRCTC Stock Price")
#convert price and chg% to numeric
rf['Price'] = pd.to_numeric(rf['Price'], errors='coerce')
rf['Chg%'] = pd.to_numeric(rf['Chg%'])
rf = rf.dropna(subset=['Price', 'Chg%'])
mean= statistics.mean(rf['Price'])#for mean
variance= statistics.variance(rf['Price'])# for variance
print("Mean of Price:", mean)
print("Variance of Price:", variance)
wed_prices = rf[rf['Day'] == 'Wed']['Price']
mean_wed = statistics.mean(wed_prices)
#we are finding mean only for wednesday
print("Mean for wednesday:", mean_wed)
print("Population Mean:", mean)
#for april data we are finding mean prices
april_prices = rf[rf['Month'] == 'Apr']['Price']
if not april_prices.empty:
mean_apr = statistics.mean(april_prices)
print("Mean for April:", mean_apr)
print("Population Mean:", mean)
else:
print("No data for April.")
#calculating probability of a loss
loss_days = rf[rf['Chg%'] < 0]
prob_loss = len(loss_days) / len(rf)
print("Probability of making a loss:", round(prob_loss, 4))
#profit for wednesday
wed = rf[rf['Day'] == 'Wed']
profit_wed_days = wed[wed['Chg%'] > 0]
profit_wed = len(profit_wed_days) / len(wed)
print("Wednesday Profit:", round(profit_wed, 4))
days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri']
rf['Day'] = pd.Categorical(rf['Day'], categories=days, ordered=True)
rf = rf.sort_values('Day')
plt.scatter(rf['Day'], rf['Chg%'], color='blue')
plt.xlabel('Day of the Week')
plt.ylabel('Chg%')
plt.title('Chg% vs Day of the Week')
plt.grid(True)
plt.show()