运行以下代码
**import pandas as pd
**
import numpy as np
# visualization
import matplotlib.pyplot as plt
%matplotlib inline
运行以下代码
**#从目标路径导入数据集
**
**path9 =
'D:/hailong/hailong_download/pandas_exercise/exercise_data/Apple_stock.csv'**
运行以下代码
**apple = pd.read_csv(path9)
**
apple.head()
输出结果
运行以下代码
**apple.dtypes
**
输出结果
运行以下代码
**apple.Date = pd.to_datetime(apple.Date)
**
apple'Date'.head()
输出结果
运行以下代码
**apple = apple.set_index('Date')
**
apple.head()
输出结果
运行以下代码
**apple.index.is_unique
**
输出结果:True
运行以下代码
**apple.sort_index(ascending = True).head()
**
输出结果
运行以下代码
**apple_month = apple.resample('BM').mean()
**
apple_month.head()
输出结果
注意: .resample()在高版本已不再使用(容易出错点)
运行以下代码
**(apple.index.max() - apple.index.min()).days
**
输出结果:12261
运行以下代码
**apple_months = apple.resample('BM').mean()
**
len(apple_months.index)
**输出结果:404
**
运行以下代码
**# makes the plot and assign it to a variable
**
apple_open = apple'Adj Close'.plot(title = "Apple stock")
# changes the size of the graph
fig = apple_open.get_figure()
fig.set_size_inches(13.5,9)
输出结果
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。