机器学习查询下面的股票代码和价值之间的关系以及为什么我会收到索引错误 [英] Machine learning queries what is relation between ticker and value below and why am I getting index error

查看:89
本文介绍了机器学习查询下面的股票代码和价值之间的关系以及为什么我会收到索引错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你们可以告诉我股票代码和价值之间的关系。 当它为1时,我得到了股票代码的索引错误,但是当改为0时,我得到的值很少,但最后我仍然得到值的值误差。如何解决这个问题任何人都可以告诉。请以简化的方式作为编程新手。



我尝试过:



导入pandas为pd

导入os

导入时间

来自日期时间导入日期时间



path =/ home / meghanaa / ML / intraQuarter



def Key_Stats(gather =总债务/权益(mrq)) :

statspath = path +'/ _ KeyStats'

stock_list = [x [0] for os in os.walk(statspath)]



for stock_list中的each_dir [1:]:

each_file = os.listdir(each_dir)

ticker = each_dir.split(\\\ \\)[0]

if len(each_file)> 0:
每个文件中的文件


date_stamp = datetime.strptime(文件,'%Y%m%d%H%M%S.html')

unix_time = time.mktime(date_stamp.timetuple())

#print(date_stamp,unix_time)

full_file_path = each_dir +'/'+ file

print(full_file_path)

source = open(full_file_path,'r')。read()

#print(source)

value = source.split(gather +':')[1] .split('')[0]

print(ticker +:,value)



time.sleep(15)

Key_Stats()



这段代码也是我的得到一个错误但是自动收报机值为1,值为-1我没有得到任何错误,但是输出不是预期的。

Hi can anyone tell me the relation between ticker and value . "I was getting an index error for ticker when it is 1 but when changed to 0 i get few values but at the end i still get value error in value ". how to resolve this issue can anyone tell. please in a simplified manner as im new to programming.

What I have tried:

import pandas as pd
import os
import time
from datetime import datetime

path = "/home/meghanaa/ML/intraQuarter"

def Key_Stats(gather="Total Debt/Equity (mrq)"):
statspath = path+'/_KeyStats'
stock_list = [x[0] for x in os.walk(statspath)]

for each_dir in stock_list[1:]:
each_file = os.listdir(each_dir)
ticker = each_dir.split("\\")[0]
if len(each_file) > 0:
for file in each_file:
date_stamp = datetime.strptime(file, '%Y%m%d%H%M%S.html')
unix_time = time.mktime(date_stamp.timetuple())
#print(date_stamp, unix_time)
full_file_path = each_dir+'/'+file
print(full_file_path)
source = open(full_file_path,'r').read()
#print(source)
value = source.split(gather+':')[1].split('')[0]
print(ticker+":",value)

time.sleep(15)
Key_Stats()

with this code also i'am getting an error but ticker value to 1 and value to -1 im not getting any error but the output is not as expected .

推荐答案

停止使用如下所示的复合语句。你无法确定(我们绝对不能)每个部分的结果是什么。将其拆分为离散元素,以便您可以在每个步骤中查看结果。然后,您可以显示临时值并查看它出错的位置。

Stop using compound statements like this below. You cannot be certain (and we definitely cannot) what is the result at each part. Split it into discrete elements so you can see the results at each step. You can then display interim values and see where it is going wrong.
value = source.split(gather+':')[1].split('')[0]


这篇关于机器学习查询下面的股票代码和价值之间的关系以及为什么我会收到索引错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆