pandas的应用第八天
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = 'SimHei'
plt.rcParams['axes.unicode_minus'] = False
%config InlineBackend.figure_format = 'svg'
ser1 = pd.Series(np.random.randint(10, 100, 10))
ser1.rolling(3).sum()
import pandas_datareader as pdr
baidu_df = pdr.get_data_stooq('BIDU', start='2021-11-1', end='2021-12-8')
baidu_df.sort_index(inplace=True)
baidu_df.Close.rolling(10).mean()
plt.plot(np.arange(baidu_df.index.size), baidu_df.Close)
plt.xticks(np.arange(baidu_df.index.size),
rotation=45,
labels=baidu_df.index.month.astype(str).values + '-' + baidu_df.index.day.astype(str).values)
plt.yticks(np.arange(100, 181, 10))
plt.show()
sales_data = np.random.randint(400, 1000, 12)
month_index = pd.RangeIndex(1, 13, name='月份')
ser = pd.Series(data=sales_data, index=month_index)
ids = np.arange(1001, 1006)
sms = ['期中', '期末']
index = pd.MultiIndex.from_product((ids, sms), names=['学号', '学期'])
courses = ['语文', '数学', '英语']
scores = np.random.randint(60, 101, (10, 3))
df = pd.DataFrame(data=scores, columns=courses, index=index)
pd.date_range('2021-1-1', '2021-6-1', periods=10)
temp = pd.date_range('2021-1-1', '2021-6-1', freq='W')
temp