np.dot(a,b) 支持矩阵和标量
np.matmul(a,b) 不支持矩阵和标量
Pandas
DataFrame
import pandas as pd
import numpy as np
x1 = pd.DataFrame(np.random.randn(2,3))
print(x1)
score = np.random.randint(40, 100, (10,5))
print(score)
score_df = pd.DataFrame(score)
print(score_df)
subjects = ["yuwen", "shuxue", "yingyu", "zhengzhi", "tiyu"]
stu = ["tongxue" + str(i) for i in range(score_df.shape[0])]
#在Python中,range(score_df.shape[0]) 是一个表示整数范围的对象。
# 它可以用于创建一个迭代器,用于循环遍历从 0 到 score_df.shape[0] - 1 的整数序列。这个范围通常用于迭代数组、列表或数据框的索引或位置。
print(stu)
data = pd.DataFrame(score, columns=subjects, index=stu)
print(data)
df = pd.DataFrame({'month': [1,4,7,10], 'year': [2012, 2014, 2013, 2014], 'sale': [55, 40, 84, 31]})
print(df)
df = df.set_index(['year','month'])
print(df.index)
print(df.index.names)
print(df.index.levels)
arrays = [[1,1,2,2],["r", "b", "r", "b" ]]
x3 = pd.MultiIndex.from_arrays(arrays,names=("num", "col"))
print(x3)
import pandas as pd
data = pd.read_csv('./BRNN/data/stock_day.csv')
print(data)
print(data.head())
#删除 axis=1 按列删除
data = data.drop(["v_ma5", "v_ma10", "v_ma20"], axis=1)
print(data)
#索引操作
x1 = data["open"]["2018-02-27"]
#先列后行 取数据 直接索引
print(x1)
x2 = data.loc["2018-02-27":"2018-02-14","open":"close"]
print(x2)
x3 = data.iloc[:5, :3]
print(x3)
x4 = data.loc[data.index[0:5], ["open", "close"]]
print(x4)
x5 = data.iloc[0:5, data.columns.get_indexer(["open", "close"])]
print(x5)