【数据分析】苹果公司股票数据处理
程序员文章站
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')
上一篇: Finder的GUI占资源太多
下一篇: egret加载资源改成进度条
推荐阅读
-
【数据分析】苹果公司股票数据处理
-
6个用于大数据分析处理的最好工具 博客分类: 大数据平台大数据应用大数据处理数据分析数据可视化 大数据大数据工具数据分析数据处理数据可视化
-
Hadoop和大数据:60款*开源工具 博客分类: 大数据平台大数据应用数据可视化大数据处理数据分析 大数据hadoop数据分析数据可视化人工智能
-
二手房数据的分析与挖掘(二)-- 数据处理
-
PHP数学运算与数据处理实例分析_php技巧
-
ELK日志分析系统(3)-logstash数据处理
-
PHP数学运算与数据处理实例分析
-
IBM将大数据分析和安全能力引入苹果移动设备
-
数据分析之pandas常见的数据处理(四)
-
流数据处理与分析