【发布时间】:2019-12-25 20:17:58
【问题描述】:
我目前正在开发一个机器学习应用程序。请在这段代码中帮助我 - 当我上传大数据集时出现错误。
代码如下:
prep_file = Prepross.objects.get_or_create(
filename = CurrentFile.objects.order_by('-id')[0].filename,
coltype = request.POST.getlist('coltype'),
assvar = request.POST.getlist('assvar'),
missingvalues = request.POST.getlist('missingvalues'),
trainingset_size = request.POST['trainingset_size'],
featscaling = request.POST.getlist('featscaling'))
然后:
# Get dataframe and change data type
context = {}
file_name = CurrentFile.objects.order_by('-id')[0].filename
coltype = request.POST.getlist('coltype')
coltype = dict([i.split(':', 1) for i in coltype])
df = pd.read_csv(os.path.join('media\downloaded', file_name), dtype= coltype)
row_count = df.count()[0]
# Keep only selected columns
assvar = request.POST.getlist('assvar')
xcols0 = [s for s in assvar if ":X" in s]
xcols = [i.split(':', 1)[0] for i in xcols0]
ycol0 = [s for s in assvar if ":y" in s]
ycol = [i.split(':', 1)[0] for i in ycol0]
cols = xcols + ycol
df = df[cols]
xcols = ', '.join(xcols)
ycol = ', '.join(ycol)
missing = request.POST.getlist('missingvalues')
missing = ', '.join(missing)
trainingset_s = request.POST.getlist('trainingset_size')
trainingset_s = ', '.join(trainingset_s)
testset_s = 100 - int(trainingset_s)
feat = request.POST['featscaling']
# Taking care of missing data
if missing == "no":
if len(df) != len(df.dropna()):
context['selecty'] = 'Your data seem to have Missing Values'
else:
df = df.dropna()
# Return error if columns are not selected
if len(ycol0) != 1:
context['selecty'] = 'Please select one y variable'
elif len(xcols0) < 1:
context['selecty'] = 'Please select one or more X variables'
错误是:
File "C:\Users\Admin\PycharmProject\mlapp\views.py", line 81, in post
coltype = dict([i.split(':', 1) for i in coltype])
ValueError: dictionary update sequence element #0 has length 1; 2 is required
[20/Aug/2019 16:43:39] "POST /preprocessing/ HTTP/1.1" 500 81482
关于错误的附加行和信息:
/preprocessing/ 处的ValueError
字典更新序列元素#0的长度为1; 2 是必需的
请求方法:POST
请求网址:http://127.0.0.1:8000/preprocessing/
Django 版本:2.2.4
异常类型:ValueError
异常值:
字典更新序列元素#0的长度为1; 2 是必需的
异常位置:C:\Users\Admin\PycharmProject\mlapp\views.py 在帖子中,第 81 行
Python 可执行文件:C:\Users\Admin\AppData\Local\Programs\Python\Python37\python.exe
Python版本:3.7.3
Python 路径:
['C:\Users\Admin\PycharmProject\freed',
'C:\Users\Admin\AppData\Local\Programs\Python\Python37\python37.zip',
'C:\Users\Admin\AppData\Local\Programs\Python\Python37\DLLs',
'C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib',
'C:\Users\Admin\AppData\Local\Programs\Python\Python37',
'C:\Users\Admin\AppData\Roaming\Python\Python37\site-packages',
'C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages']
服务器时间:2019年8月20日星期二13:27:32 +0000
【问题讨论】:
标签: python django machine-learning