2018-12-10
阅读量:
796
python里怎么恢复数据
要返回原始数据Series
或NumPy数组,请使用Series.astype(original_dtype)
或np.asarray(categorical)
:
s = pd.Series(["a","b","c","a"])
s
0 a
1 b
2 c
3 a
dtype: object
s2 = s.astype('category')
s2
0 a
1 b
2 c
3 a
dtype: category
Categories (3, object): [a, b, c]
s2.astype(str)
0 a
1 b
2 c
3 a
dtype: object
np.asarray(s2)
array(['a', 'b', 'c', 'a'], dtype=object)
注意
与R的因子函数相反,分类数据不是将输入值转换为字符串; 类别将与原始值结束相同的数据类型。
注意
与R的因子函数相比,目前无法在创建时分配/更改标签。使用类别在创建时间后更改类






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论