AttributeError:“列表”对象属性“索引”为只读

时间:2019-11-18 13:56:43

标签: python tensorflow socketserver

我是python编程的新手。我尝试将tensorflow与MT4数据连接起来。我使用一种可行的解决方案来传输数据,但有一些问题可以将其添加到tensorflow中。我尝试使用基本的时间序列预测。

def train_test_model(msg=''):
   msg = msg.replace('true', 'True')
   msg = ast.literal_eval(msg)

   print(type(msg))

   if (type(msg) == dict):
    input_data = msg
   else:
    return "BAD JSON!!"

   uni_data = input_data['Data']
   uni_data.index = input_data['Time']

   uni_data = uni_data.values

   uni_train_mean = uni_data[:TRAIN_SPLIT].mean()
   uni_train_std = uni_data[:TRAIN_SPLIT].std()

   uni_data = (uni_data - uni_train_mean) / uni_train_std

我得到的是: AttributeError:“列表”对象属性“索引”为只读

这是获取数据的套接字服务器:

class socketserver:
    def __init__(self, address='', port=9090):
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.address = address
        self.port = port
        self.sock.bind((self.address, self.port))
        self.cummdata = ''

    def recvmsg(self):
        self.sock.listen(1)
        self.conn, self.addr = self.sock.accept()
        print('connected to', self.addr)
        self.cummdata = ''

        while True:
            data = self.conn.recv(10000000)
            self.cummdata += data.decode("utf-8")

            if not data:
                break
            self.conn.send(bytes(train_test_model(self.cummdata), "utf-8"))

            return self.cummdata

1 个答案:

答案 0 :(得分:0)

您不能将任何值分配给对象的只读属性。 https://localhost:44346/api/students/postStudentListindex的{​​{1}}属性。您要如何处理read-only行?也许您希望list成为uni_data.index = input_data['Time']数据框?如果是,则用uni_data固定该行,不要忘了pandas

单人信贷