-
Notifications
You must be signed in to change notification settings - Fork 0
/
ps3.py
37 lines (23 loc) · 937 Bytes
/
ps3.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 11 16:05:43 2022
@author: echellwig
"""
import pandas as pd #load pandas and call it pd
#set options so large numbers are not converted to scientific notation
pd.set_option('display.float_format', lambda x: '%.2f' % x)
#create data frame from csv
sales = pd.read_csv('data/raw_sales.csv')
#some data manipulation
sales['postcode'] = sales['postcode'].astype(str)
sales['postcode'] = '0' + sales['postcode']
sales['datesold'] = pd.to_datetime(sales['datesold'], format="%Y-%m-%d %H:%M:%S")
# Question 1
sales['Month'] = sales.datesold.dt.to_period('M')
# Question 7
price_ts = sales.loc[sales.postcode=='02615'].groupby(['Month'], as_index=False).price.mean()
price_ts = sales.loc[sales.postcode=='02615'].groupby(['Month'], as_index=False).price.mean()
price_ts['RollingAvg'] = price_ts.price.rolling(12).mean()
price_ts
price_ts.dropna(inplace=True)