import pandas as pd
import numpy as np s = pd.Series(np.random.rand(5), index=list('abcde'))
# 创建序列,其中 index=list('abcde')为每一行添加索引
s.index.name='alpha' # 为行索引添加名称标签 df = pd.DataFrame(np.random.randn(4,3), columns=['one','two','three'])
# 创建DataFrame,其中columns=['one','two','three']表示为每一列添加索引
df.index.name = 'row' # 为行索引添加名称标签
df.columns.name = 'col' # 为列索引添加名称标签
 import pandas as pd
import numpy as np s = pd.Series(np.arange(6), index=list('abcbda'))
# 创建一个带有重复索引的Series s['a'] # 找出a的所有索引对应的值
s.index.is_unique # 判断s中每个索引是否独一无二
s.index.unique() # 找出s中不重复的索引 s.groupby(s.index).sum() # 将索引分组并求和
s.groupby(s.index).mean() # 将索引分组并求均值
s.groupby(s.index).first() # 将索引分组并取第一项
 import pandas as pd
import numpy as np a = [['a','a','a','b','b','c','c'],[1,2,3,1,2,2,3]]
t = list(zip(*a))
index = pd.MultiIndex.from_tuples(t,names=['level1','level2'])
s = pd.Series(np.random.rand(7),index=index)
# 输出 s
level1 level2
a 1 0.029233
2 0.539508
3 0.502217
b 1 0.536222
2 0.217398
c 2 0.551864
3 0.596248 s['b']
# 输出
level2
1 0.536222
2 0.217398
dtype: float64 s['b':'c']
# 输出
level1 level2
b 1 0.536222
2 0.217398
c 2 0.551864
3 0.596248
dtype: float64 s[['a','c']]
# 输出
level1 level2
a 1 0.029233
2 0.539508
3 0.502217
c 2 0.551864
3 0.596248
dtype: float64 s[:,2]
# 输出
level1
a 0.539508
b 0.217398
c 0.551864
dtype: float64

pandas 索引笔记的更多相关文章

  1. 【转】Pandas学习笔记(六)合并 merge

    Pandas学习笔记系列: Pandas学习笔记(一)基本介绍 Pandas学习笔记(二)选择数据 Pandas学习笔记(三)修改&添加值 Pandas学习笔记(四)处理丢失值 Pandas学 ...

  2. 【转】Pandas学习笔记(三)修改&添加值

    Pandas学习笔记系列: Pandas学习笔记(一)基本介绍 Pandas学习笔记(二)选择数据 Pandas学习笔记(三)修改&添加值 Pandas学习笔记(四)处理丢失值 Pandas学 ...

  3. 【转】Pandas学习笔记(二)选择数据

    Pandas学习笔记系列: Pandas学习笔记(一)基本介绍 Pandas学习笔记(二)选择数据 Pandas学习笔记(三)修改&添加值 Pandas学习笔记(四)处理丢失值 Pandas学 ...

  4. 【转】Pandas学习笔记(一)基本介绍

    Pandas学习笔记系列: Pandas学习笔记(一)基本介绍 Pandas学习笔记(二)选择数据 Pandas学习笔记(三)修改&添加值 Pandas学习笔记(四)处理丢失值 Pandas学 ...

  5. Pandas 学习笔记

    Pandas 学习笔记 pandas 由两部份组成,分别是 Series 和 DataFrame. Series 可以理解为"一维数组.列表.字典" DataFrame 可以理解为 ...

  6. 【转】Pandas学习笔记(七)plot画图

    Pandas学习笔记系列: Pandas学习笔记(一)基本介绍 Pandas学习笔记(二)选择数据 Pandas学习笔记(三)修改&添加值 Pandas学习笔记(四)处理丢失值 Pandas学 ...

  7. 【转】Pandas学习笔记(五)合并 concat

    Pandas学习笔记系列: Pandas学习笔记(一)基本介绍 Pandas学习笔记(二)选择数据 Pandas学习笔记(三)修改&添加值 Pandas学习笔记(四)处理丢失值 Pandas学 ...

  8. 【转】Pandas学习笔记(四)处理丢失值

    Pandas学习笔记系列: Pandas学习笔记(一)基本介绍 Pandas学习笔记(二)选择数据 Pandas学习笔记(三)修改&添加值 Pandas学习笔记(四)处理丢失值 Pandas学 ...

  9. pandas读书笔记、重新索引

      重新索引   pandas对象的一个重要方法是 reindex ,其作用是创建一个适应新索引的新对象. #reindex函数的参数 reindex(index,method,fill_value, ...

随机推荐

  1. Vue进阶(Bus/作用域slot/动态组件)

    一.Vue非父子组件传值(Bus/总线/发布订阅模式/观察者模式) 我们在之前已经知道了父子传值.父组件传递过来了的值,在子组件通过props接受,然后就可以使用了. 也学过了隔代传值,均是通过pro ...

  2. mysql数据库单独移动位置

    在新版本中.sym方式已不再支持,最新的方式是使用软链接方式(Windows),官方文档:https://dev.mysql.com/doc/refman/5.7/en/windows-symboli ...

  3. LeetCode31 Next Permutation and LeetCode60 Permutation Sequence

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  4. oracle之nvl,nvl2,decode

    oracle sql常用查询nvl,nvl2,decode区别及使用方法 1,NVL( E1, E2) 如果E1为NULL,则NVL函数返回E2的值,否则返回E1的值,如果两个参数都为NULL ,则返 ...

  5. javaWeb项目部署到阿里云服务器

    1.云服务器中配置了jdk+eclipse+tomcat 2.将项目导出War到安装的Tomcat的webapps文件夹中: 右击项目->Export->WarFile->Desti ...

  6. OpenResty之replace-filter-nginx-module

    原文: openresty/replace-filter-nginx-module 1. 概要 location /t { default_type text/html; echo abc; repl ...

  7. appium 小程序自动化测试

    https://www.cnblogs.com/yoyoketang/p/9144987.html adb shell su ACTIVITY com.tencent.mm/.plugin.appbr ...

  8. GO --- 将Reader 或者 ReadCloser 转化为 ReadSeeker

    原因: ReadSeeker 封装了Seek()方法,这个方法要求资源的任何位置都能被定位,例如存储在磁盘里文件,你可以随时读取文件的任意位置.而response.Body 是通过TCP连接从网络中读 ...

  9. How to transform the day time images to night time ? A series of paper review and some thinkings about this point.

    How to transform the day time images to night time ?  A series of paper review and some thinkings ab ...

  10. VIM快速掌握

    vi/vim 基本使用方法 vi编辑器是所有Unix及Linux系统下标准的编辑器,它的强大不逊色于任何最新的文本编辑器,这里只是简单地介绍一下它的用法和一小部分指令.由于对Unix及Linux系统的 ...