<jupyter_start><jupyter_text>Apple Stock 分析苹果股票 导包<jupyter_code>import matplotlib.pyplot as plt
%matplotlib inline

import numpy as np

import pandas as pd
from pandas import Series,DataFrame<jupyter_output><empty_output><jupyter_text>读取数据<jupyter_code>apple = pd.read_csv('./AAPL.csv')
display(apple.shape,apple.head())<jupyter_output><empty_output><jupyter_text>检查数据类型<jupyter_code>apple.dtypes
type(apple['Date'][0])<jupyter_output><empty_output><jupyter_text>将'Date'这行数据转换为时间数据类型<jupyter_code>appl = apple.copy()
apple['Date'] = pd.to_datetime(apple['Date'])<jupyter_output><empty_output><jupyter_text>查看数据类型<jupyter_code>apple.head()
apple.dtypes
apple.set_index('Date',inplace=True)
apple.head()
# 因为股票价格，每一天都在波动
# 分组属性，必须要有共同属性，便于分组
grouped = apple.groupby('Adj Close')
# 重采样：根据时间进行划分 划分成天D，划分成月M，划分成年Y
grouped.resample('M').mean()
apple.index<jupyter_output><empty_output><jupyter_text>将'Date'设置为行索引  绘制图形，字段Adj Close：已调整收盘价格<jupyter_code>plt.figure(figsize=(12,9))
apple['Adj Close'].plot()
appl.set_index('Date',inplace=True)
appl.head()
appl['Adj Close'].plot()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15335753176043557, 'fraction_numerical': 0.003629764065335753, 'mean_word_length': 12.7875, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '290214', 'license': 'Apache-2.0', 'n_tokens_mistral': 521, 'n_tokens_neox': 550, 'n_words': 47, 'path': 'jupyterlab/day05/code/4-pandas/softpo/Apple-Stock.ipynb', 'repo_name': 'marxlee/py-data-process', 'size': '1102'}