ndarray、Series、DateFrame类型

ndarray类型(来自numpy)

n维数据类型
关注数据的结构表达(数据的维度)

ndarray的切片和索引

ndarray的计算

Series类型(来自pandas)

一维
关注数据与索引的关系
自动索引
自定义索引(index)
两套索引并存,但不能混用
Series类型通过自定义索引进行切片和索引,与ndarray类型用法相同

*可以由字典创建,字典的键自动转换位Series的索引

Series类型的操作
.index
.value
.name

Series类型的操作

DateFrame(来自pandas)

二维(也可以表达多维,但不常用)
关注数据与索引的关系
定义:共用相同索引的数据
行索引:index
列索引:columns

DataFrame类型的索引和切片
有4种方式

x = np.arange(24).reshape(4,6)
y = pd.DataFrame(x,index = ['A','B','C','D'],columns = ['a','b','c','d','e','f'])
print(y,'\n')
>>>
    a   b   c   d   e   f
A   0   1   2   3   4   5
B   6   7   8   9  10  11
C  12  13  14  15  16  17
D  18  19  20  21  22  23 

y[]
y.loc[]
y.iloc[]
y.ix[]

其中,
y[]只能用来按行切片,或者获取某列数据;
y.loc[]利用自定义行索引和列索引进行切片或数据选择,在没有自定义索引时,自动索引相当于自定义索引;
y.iloc[]利用自动行索引和列索引进行切片或数据选择;
y.ix[]可混合使用自定义索引和自动索引,但不推荐使用;

#行重排
.reindex(index = [])
#列重排
.reindex(column = [])

按索引重新排序
pd.DataFrame.sort_index
sort_index(self, axis=0, level=None, ascending=True, inplace=False, kind=‘quicksort’, na_position=‘last’, sort_remaining=True, by=None)
Sort object by labels (along an axis)

Parameters
----------
axis : index, columns to direct sorting
level : int or level name or list of ints or list of level names
if not None, sort on values in specified index level(s)
ascending : boolean, default True
Sort ascending vs. descending
是否覆盖原数据
inplace : bool, default False
if True, perform operation in-place
kind : {‘quicksort’, ‘mergesort’, ‘heapsort’}, default ‘quicksort’
Choice of sorting algorithm. See also ndarray.np.sort for more
information. mergesort is the only stable algorithm. For
DataFrames, this option is only applied when sorting on a single
column or label.
na_position : {‘first’, ‘last’}, default ‘last’
first puts NaNs at the beginning, last puts NaNs at the end.
Not implemented for MultiIndex.
sort_remaining : bool, default True
if true and sorting by level and index is multilevel, sort by other
levels too (in order) after sorting by specified level
Returns
-------
sorted_obj : DataFrame

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值