英文:
in python, i am using pandas to read a csv file when its working fine tho with other functions but facing an error while using a line
问题
我导入了panda作为pd
dataset = pd.read_csv('C:\\Users\\Adminis....')
dataset.plot(x='tempmin', y='tempmax', style='o')
pit.show()
pit.figure(figsize=(15,10)) #这些都正常运行
pit.tight_layout()
seaborninstance.distplot(dataset['tempmax'])
pit.show()
但是在使用这个时出现了问题
x = dataset['tempmin'].values.reshape(-1,-1)
y = dataset['tempmax'].values.reshape(-1,-1)
x = dataset['tempmin'].values.reshape(-1,-1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: 只能指定一个未知维度
我原本期望使用这个来训练我的算法,但我卡在一个变量上了?
英文:
i imported panda as pd
dataset = pd.read_csv('C:\\Users\\Adminis....')
dataset.plot(x='tempmin', y='tempmax', style='o')
pit.show()
pit.figure(figsize=(15,10)) #these are working fine
pit.tight_layout()
seaborninstance.distplot(dataset['tempmax'])
pit.show()
but i am getting in trouble while using this
x = dataset['tempmin'].values.reshape(-1,-1)
y = dataset['tempmax'].values.reshape(-1,-1)
x = dataset['tempmin'].values.reshape(-1,-1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: can only specify one unknown dimension
i was expecting to use this to train my algo but i am stuck on a variable??
答案1
得分: 0
在reshape
函数中,只能有一个维度的大小未指定。我猜你想要将数据框的列转换为列向量,以输入到某个训练模块中,那么你需要将其重塑为(-1, 1)而不是(-1, -1),即:
x = dataset['tempmin'].values.reshape(-1, 1)
y = dataset['tempmax'].values.reshape(-1, 1)
英文:
Only one dimension size can be unspecified in reshape
function. I guess you want to convert the dataframe columns to column vectors to feed into some training module, then you need to reshape to (-1, 1) not (-1, -1), i.e.
x = dataset['tempmin'].values.reshape(-1, 1)
y = dataset['tempmax'].values.reshape(-1, 1)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论