欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【数据分析】苹果公司股票数据处理

程序员文章站 2024-03-20 19:56:34
...
import numpy as np

import pandas as pd

from pandas import Series,DataFrame
app = pd.read_csv('./AAPL.csv')

app.shape
(9814, 7)
app.head()
Date Open High Low Close Adj Close Volume
0 1980-12-12 0.513393 0.515625 0.513393 0.513393 0.407747 117258400.0
1 1980-12-15 0.488839 0.488839 0.486607 0.486607 0.386473 43971200.0
2 1980-12-16 0.453125 0.453125 0.450893 0.450893 0.358108 26432000.0
3 1980-12-17 0.462054 0.464286 0.462054 0.462054 0.366972 21610400.0
4 1980-12-18 0.475446 0.477679 0.475446 0.475446 0.377609 18362400.0
app.tail()
Date Open High Low Close Adj Close Volume
9809 2019-11-06 256.769989 257.489990 255.369995 257.239990 256.470001 18966100.0
9810 2019-11-07 258.739990 260.350006 258.109985 259.429993 259.429993 23735100.0
9811 2019-11-08 258.690002 260.440002 256.850006 260.140015 260.140015 17496600.0
9812 2019-11-11 258.299988 262.470001 258.279999 262.200012 262.200012 20455300.0
9813 2019-11-12 261.549988 262.790009 260.920013 261.959991 261.959991 21826100.0
app.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 9814 entries, 0 to 9813
Data columns (total 7 columns):
Date         9814 non-null object
Open         9813 non-null float64
High         9813 non-null float64
Low          9813 non-null float64
Close        9813 non-null float64
Adj Close    9813 non-null float64
Volume       9813 non-null float64
dtypes: float64(6), object(1)
memory usage: 536.8+ KB
app[app.isnull().any(axis = 1)]
Date Open High Low Close Adj Close Volume
165 1981-08-10 NaN NaN NaN NaN NaN NaN
app.dropna(inplace = True)
app.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 9813 entries, 0 to 9813
Data columns (total 7 columns):
Date         9813 non-null object
Open         9813 non-null float64
High         9813 non-null float64
Low          9813 non-null float64
Close        9813 non-null float64
Adj Close    9813 non-null float64
Volume       9813 non-null float64
dtypes: float64(6), object(1)
memory usage: 613.3+ KB
app['Date'] = pd.to_datetime(app['Date'])
app.dtypes
Date         datetime64[ns]
Open                float64
High                float64
Low                 float64
Close               float64
Adj Close           float64
Volume              float64
dtype: object
app.head()
Date Open High Low Close Adj Close Volume
0 1980-12-12 0.513393 0.515625 0.513393 0.513393 0.407747 117258400.0
1 1980-12-15 0.488839 0.488839 0.486607 0.486607 0.386473 43971200.0
2 1980-12-16 0.453125 0.453125 0.450893 0.450893 0.358108 26432000.0
3 1980-12-17 0.462054 0.464286 0.462054 0.462054 0.366972 21610400.0
4 1980-12-18 0.475446 0.477679 0.475446 0.475446 0.377609 18362400.0
app2 = app.set_index('Date')
app2
Open High Low Close Adj Close Volume
Date
1980-12-12 0.513393 0.515625 0.513393 0.513393 0.407747 117258400.0
1980-12-15 0.488839 0.488839 0.486607 0.486607 0.386473 43971200.0
1980-12-16 0.453125 0.453125 0.450893 0.450893 0.358108 26432000.0
1980-12-17 0.462054 0.464286 0.462054 0.462054 0.366972 21610400.0
1980-12-18 0.475446 0.477679 0.475446 0.475446 0.377609 18362400.0
... ... ... ... ... ... ...
2019-11-06 256.769989 257.489990 255.369995 257.239990 256.470001 18966100.0
2019-11-07 258.739990 260.350006 258.109985 259.429993 259.429993 23735100.0
2019-11-08 258.690002 260.440002 256.850006 260.140015 260.140015 17496600.0
2019-11-11 258.299988 262.470001 258.279999 262.200012 262.200012 20455300.0
2019-11-12 261.549988 262.790009 260.920013 261.959991 261.959991 21826100.0

9813 rows × 6 columns

app2['Adj Close'].plot(kind ='line')
<matplotlib.axes._subplots.AxesSubplot at 0x1ddedad8d68>

【数据分析】苹果公司股票数据处理

app2.resample('M').median().plot(kind ='line')
<matplotlib.axes._subplots.AxesSubplot at 0x1ddedae2710>

【数据分析】苹果公司股票数据处理


app2.resample('M').median()[['Adj Close','Open']].plot(kind ='line')

【数据分析】苹果公司股票数据处理


app2.resample('Y').median()[['High','Low']].plot(kind ='line')

【数据分析】苹果公司股票数据处理

相关标签: 数据分析 apple