1.问题描述
AttributeError: 'Series' object has no attribute 'reshape'
属性错误: ‘Series’ 对象没有属性 ‘reshape’
a.什么是 ‘Series’ 对象?
答:Series对象类似一维数组,但与数组不同的是,Series对象不仅可以像数组那样支持下标索引。还可以自建索引,像字典一样使用索引。
sel = Series([1,2,3,4])
按下标索引
sel[1]是2
自建索引
sel = Series(data = [1,2,3,4],index=['a','b','c','d'])
sel['c']是3
b.为什么 ‘Series’ 对象没有 'reshape’属性?
前面介绍了,Series对象类似一维数组。而’reshape’属性是ndarray等对象有的。
reshape可以用于numpy库里的ndarray和array结构以及pandas库里面的DataFrame和Series结构。
解决这个问题
使用Series’ 对象的values属性,然后再使用reshape方法.
sel = Series([1,2,3,4])
sel.values.reshape(-1,1)
#reshape来更改数据的列数和行数
#(-1,1)把数据转化为一列
#(1,-1)表示把数据转化为一行