-
Notifications
You must be signed in to change notification settings - Fork 10
/
final_project_Xiaonan_Yang.py
77 lines (36 loc) · 1.63 KB
/
final_project_Xiaonan_Yang.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# coding: utf-8
# In[9]:
# In the past year, Bitcoin has been fluctuated frequently - the highest market price was over USD19,000, the lowest market price was around USD2,000, and there was approximately 6 main fluctuations. In this project, my goal is to find out when the best timing is to buy Bitcoin. To achieve this goal, the mean value of Bitcoin's market price and snapped price will be viuslized. The dataset is download from coingecko.com
import pandas as pd
# In[17]:
#import the data set
data = pd.read_csv(r'C:\Users\seany\OneDrive\Documents\btc_usd.csv')
#create a dataframe of this dataset
df = pd.DataFrame(data)
df
# In[23]:
#two of clomuns in this dataset is useless for this project, so I deleted them from the dataframe
df.drop(columns=['market_cap','total_volume'])
# In[39]:
#change the index of this dataset from number to the date
df.index = df['snapped_at']
df.head
# In[27]:
#create the plot of the price change
get_ipython().run_line_magic('pylab', 'inline')
df['price'].plot(kind = 'line', figsize = [10,6])
# In[29]:
#find the mean value at each week, and name the mean value as "ma7"
df['ma7'] = df['price'].rolling(window = 7).mean()
df['ma7'].head
# In[34]:
#plot the whole graph of the market price and weekly average market price
df[['price','ma7']].plot(kind = 'line',figsize =[20,10])
# In[35]:
#find out last month's market price vs average price
df2 = df[df['snapped_at'] >= '2018-06-03 00:00:00 UTC']
# In[36]:
df2.head
# In[37]:
#plot last month's market price and average price, so that I can know the best timing to buy the Bitcoin
df2[['price','ma7']].plot(kind = 'line',figsize =[20,10])