如何让python代码(Spyder)定位和提取数据文件?

2024-10-02 18:19:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个材料科学的机器学习项目,这个代码要求我选择要上传的文件,但是当我给这些文件命名时,它会出现一个错误消息。代码开头(及相关位)如下:

import xlrd
import re
import numpy
from sklearn import svm
from sklearn import preprocessing
from sklearn import tree
from sklearn.ensemble import RandomForestClassifier
import random
import os
from xlutils.copy import copy
import xlsxwriter
import graphviz


def main():

    pastExperiments = StoredData()
    response = input('Do you wish to use continuous representation of discreet data if available data? y or n\t')
    if response == 'y':
        pastExperiments.useContinuousRepresentation = True
    else:
        pastExperiments.useContinuousRepresentation = False

    response = input('Do you want to choose import data? y or n\t')
    if response == 'y':

        while response == 'y':
            nameOfFile = input('What is the name of the file you wish to import.\t')
            pastExperiments.importFile('./Input/' + nameOfFile)
            response = input('Do you wish to import additional data? y or n\t')
        #At this point all training data should have been imported.

    else:
        folder = os.fsencode('Input')
        for inputFile in os.listdir(folder):
            fileName = os.fsdecode(inputFile)
            if fileName.endswith(".xlsx"):
                pastExperiments.importFile('./Input/' + fileName)
            else:
                continue

以下是我收到的错误消息:

^{pr2}$

谢谢!在


Tags: ortofromimportyouinputdataif