python大数据股票分析

该代码示例展示了如何使用Python的pandas和numpy库对Excel文件中的股票数据进行处理,包括计算涨跌幅、分析成交量活跃度、统计各区间股票数量、以及根据涨跌幅和成交量给股票打分。此外,还涉及数据排序和排名的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import  pandas as pd
import numpy as np
# 读取Excel文件,pd.read_excel(r'文件位置\文件名称.xlsx')
hq = pd.read_excel(r'D:\火狐下载\股票行情20230406.xlsx')  # hq=行情
print(hq)
print(hq.shape)  # (2807, 13)
hq["涨跌幅"] = np.zeros((2807,1))  # 每种方法用完运行一次这段代码以重置数据

# 计算涨跌幅并填充
# 方法一:用while循环
i = 0
while i < hq.shape[0]:  # hq.shape[0]=2807
    hq.loc[i,"涨跌幅"] = round((hq.loc[i,"今收"] / hq.loc[i,"前收"] - 1) * 100, 2)
    i += 1
print(hq)
# 方法二:用for循环
for i in range(0,hq.shape[0]):
    hq.loc[i,"涨跌幅"] = round((hq.loc[i,"今收"] / hq.loc[i,"前收"] - 1) * 100, 2)
print(hq)
# 方法三:直接进行列运算
hq["涨跌幅"] = round((hq["今收"] / hq["前收"] - 1) * 100,2)
print(hq)

#成交量分析
import  pandas as pd
import numpy as np
hq = pd.read_excel(r'D:\火狐下载\股票行情20230406.xlsx')  # hq=行情
hq["成交量分析"] = np.zeros((hq.shape[0],1))
#用while
i = 0
while i < hq.shape[0]:
    a = hq.iloc[i,9]
    a = float(a.replace(",",""))
    if a < 1000:
        hq.loc[i,"成交量分析"] = "不活跃"
    elif a < 2000:
        hq.loc[i, "成交量分析"] = "一般"
    else:
        hq.loc[i, "成交量分析"] = "活跃"
    i += 1
#用for
for i in range(hq.shape[0]):
    a = hq.iloc[i,9]
    a = float(a.replace(",",""))
    if a < 1000:
        hq.loc[i,"成交量分析"] = "不活跃"
    elif a < 2000:
        hq.loc[i, "成交量分析"] = "一般"
    else:
        hq.loc[i, "成交量分析"] = "活跃"

#统计各区间股票数量
#方法一
Small,Medium,Large = 0,0,0
for i in range(hq.shape[0]):
    a = hq.iloc[i,9]
    a = float(a.replace(",",""))
    if a < 1000:
        hq.loc[i,"成交量分析"] = "不活跃"
        Small += 1
    elif a < 2000:
        hq.loc[i, "成交量分析"] = "一般"
 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值