pandas基础

#数组排序
fr1 = DataFrame(np.arange(8).reshape((2,4)), index=['three', 'one'], columns=['d', 'a', 'b', 'c'])
print (fr1)
print (fr1.sort_index())
print (fr1.sort_index(ascending=False))     #降序排序
print (fr1.sort_index(axis=1))
print (fr1.sort_index(axis=1, ascending=False))     #降序排序

#默认为使用索引排序

s1 = Series(range(4), index=['d','a','b','c'])

print (s1.sort_index())

s2 =Series([4, np.nan, 7, np.nan, -3, 2])
print (type(s1))
print (type(s2))
print (s2.sort_index())
print (s2.sort_values())
print (s2.sort_values(ascending=False))

 

DateFrame中,loc与iloc的区别:

loc使用的是列名称与索引名称作为位置的查找点,如下:

df1 = pd.DataFrame([[10,50],[20,60],[30,70],[40,80]], columns=['number1', 'number2'], index=['a','b','c','d'])
print (type(df1.loc['a']))
print (type(df1.loc[['a']]))
print (df1.loc[['a','d'],'number1'])        #loc,代表行和列标签,以逗号分割
print (df1.loc['a','number2'])              #二维坐标
print (df1.loc[:, 'number2'])

iloc则是相当于把表进行进行数字位置化,然后全部使用数字进行操作:

print (df1.iloc[0,0])
print (df1.iloc[[0,3], 0])
print (df1.iloc[0:4,1])
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值