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

huangapple go评论69阅读模式
英文:

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)

huangapple
  • 本文由 发表于 2023年2月26日 19:12:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75571582.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定