pandas-01 Series()的几种创建方法

pandas.Series()的几种创建方法。

import numpy as np
import pandas as pd # 使用一个列表生成一个Series
s1 = pd.Series([1, 2, 3, 4])
print(s1)
'''
0 1
1 2
2 3
3 4
dtype: int64
'''
# 返回所有的索引
print(s1.index)
'''
RangeIndex(start=0, stop=4, step=1)
'''
# 使用数组生成一个Series
s2 = pd.Series(np.arange(7))
print(s2)
'''
0 0
1 1
2 2
3 3
4 4
5 5
6 6
dtype: int64
''' # 使用一个字典生成Series,其中字典的键,就是索引
s3 = pd.Series({'1':1, '2':2, '3':3})
print(s3)
print(s3.values)
print(s3.index)
'''
1 1
2 2
3 3
dtype: int64
[1 2 3]
Index(['1', '2', '3'], dtype='object')
''' # 使用列表生成序列,并且指定索引
s4 = pd.Series([1, 2, 3, 4], index=['A', 'B', 'C', 'D'])
print(s4)
'''
A 1
B 2
C 3
D 4
dtype: int64
''' # 通过索引查找值
print(s4['A']) # 1 print(s4[s4>2])
'''
C 3
D 4
dtype: int64
''' # 将Series转换为字典
print(s4.to_dict()) # {'B': 2, 'D': 4, 'C': 3, 'A': 1} s5 = pd.Series(s4.to_dict())
print(s5)
'''
A 1
B 2
C 3
D 4
dtype: int64
''' # 为s5指定一个新的索引
index_1 = ['A', 'B', 'C', 'D', 'E']
s6 = pd.Series(s5, index=index_1)
print(s6)
'''
A 1.0
B 2.0
C 3.0
D 4.0
E NaN
dtype: float64
''' # 判断s6的每一项是否为nan
print(s6.isnull())
'''
A False
B False
C False
D False
E True
dtype: bool
'''
print(s6.notnull())
'''
A True
B True
C True
D True
E False
dtype: bool
''' # 为 series 命名
s6.name = 'demo'
print(s6)
'''
A 1.0
B 2.0
C 3.0
D 4.0
E NaN
Name: demo, dtype: float64
''' # 为 索引 命名
s6.index.name = 'demo index'
print(s6)
'''
demo index
A 1.0
B 2.0
C 3.0
D 4.0
E NaN
Name: demo, dtype: float64
'''

pandas-01 Series()的几种创建方法的更多相关文章

  1. Pandas 数据结构Series:基本概念及创建

    Series:"一维数组" 1. 和一维数组的区别 # Series 数据结构 # Series 是带有标签的一维数组,可以保存任何数据类型(整数,字符串,浮点数,Python对象 ...

  2. RealSense开发-Session和SenseManager的几种创建方法

    从Intel RealSense 的SDK文档对其架构(如图1所示)的始描述可知,Session是SDK应用的主控模块,必须在所有模块操作之前创建,并且在所有模块注销后最后注销.SenseManage ...

  3. OpenCV基本图像容器Mat的几种创建方法

    參考文章:http://www.cnblogs.com/tornadomeet/archive/2012/07/19/2599376.html 实验说明: (引用) 本文主要讲一些opencv 2.0 ...

  4. Java 数组的三种创建方法

    public static void main(String[] args) { //创建数组的第一种方法 int[] arr=new int[6]; int intValue=arr[5]; //S ...

  5. Java 数组的三种创建方法,数组拷贝方法

    public static void main(String[] args) {//创建数组的第一种方法int[] arr=new int[6];int intValue=arr[5];//Syste ...

  6. JavaScript 对象的几种创建方法

    /** * Created by 2016 on 2016/6/4. */ function Box(){ var obj = new obj(); obj.name = "Lee" ...

  7. 几种创建XMLHttpRequest对象的方法

    XMLHttpRequest对象,也就是Ajax交互的核心对象. 这里列举三种创建Ajax对象的方法. 第一种: <!DOCTYPE html> <html> <head ...

  8. Js基础知识4-函数的三种创建、四种调用(及关于new function()的解释)

    在js中,函数本身属于对象的一种,因此可以定义.赋值,作为对象的属性或者成为其他函数的参数.函数名只是函数这个对象类的引用. 函数定义 // 函数的三种创建方法(定义方式) function one( ...

  9. JavaScript 闭包的详细分享(三种创建方式)(附小实例)

    JavaScript闭包的详细理解 一.原理:闭包函数--指有权访问私有函数里面的变量和对象还有方法等:通俗的讲就是突破私有函数的作用域,让函数外面能够使用函数里面的变量及方法. 1.第一种创建方式 ...

随机推荐

  1. DesktopSharing<转>

    https://github.com/PHZ76/DesktopSharing/tree/e1543975576e6c4fc5c2404b2f4c9c99c0350bd3 git:https://gi ...

  2. python mysql数据库压力测试

    python mysql数据库压力测试 pymysql 的执行时间对比 1,装饰器,计算插入1000条数据需要的时间 def timer(func): def decor(*args): start_ ...

  3. ThinkPHP 5.1 跨域中间件

    <?php namespace app\http\middleware; class CrossDomain { public function handle($request, \Closur ...

  4. IM (二):数据通信协议的选择

    https://www.jianshu.com/p/e9c2b7c48c34 http://www.52im.net/thread-283-1-1.html https://github.com/Ja ...

  5. sumdoc t3 final dir.txt

    C:\Users\zhoufeiyue\Documents\sumdoc t3 final\sumdoc t3 final dir.txtC:\Users\zhoufeiyue\Documents\s ...

  6. Linux下安装.NET Core

    环境 { "操作系统":"CentOS 7.5 64位", "CPU":"1核", "内存":&qu ...

  7. Doker容器部署Tomcat服务器

    1.拉取tomcat服务镜像文件 root@ubuntu:~# docker pull registry.cn-hangzhou.aliyuncs.com/xxxx/xxxxx:web web: Pu ...

  8. ETF:现金替代标志

    替代标志.表示该成份证券是否可被现金替代 0 – 沪市不可被替代 1 – 沪市可以被替代 2 – 沪市必须被替代 3 – 深市退补现金替代 4 – 深市必须现金替代 5 – 非沪深市场成分证券退补现金 ...

  9. idea 添加自定义的todo标签

    背景:idea添加自定义的todo标签可以提高开发效率,搞之 在idea定义个人风格的todo IDEA自定义TODO注释 主要分为如下两步 自定义todo标签 settings>Editor& ...

  10. Linux安装zookeeper3.5.6

    依赖JRE[我这边是JRE8] 一,先在https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/stable/下载apache-zookeeper- ...