Pandas入门程序

import pandas as pd
import numpy as np

# 均值为0,标准差为1,十行五列
stock_change = np.random.normal(0, 1, (10, 5))
stock_rise = pd.DataFrame(stock_change)

# 构建行索引序列
stock_code = ["股票{}".format(i+1) for i in range(stock_rise.shape[0])]

# B是指工作日,跳过周六日
data = pd.date_range(start="20210101", periods=stock_rise.shape[1], freq="B")

# 第一个值传ndarray ,index传行索引,column传列索引
stock_c = pd.DataFrame(stock_change, index=stock_code, columns=data)

print(stock_c)
print(stock_c.shape)
print(stock_c.index)
print(stock_c.columns)
print(stock_c.values)
print(stock_c.T)
print(stock_c.head(2))
print(stock_c.tail(5))

运行结果

原文地址:https://www.cnblogs.com/yeyueweiliang/p/14283740.html