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. unzip解压失败( cannot find zipfile directory)

    本文链接:https://blog.csdn.net/yori_chen/article/details/80493383[root@localhost soft]# unzip QY.zip Arc ...

  2. 超实用!手把手教你如何用MSF进行后渗透测试!

    在对目标进行渗透测试的时候,通常情况下,我们首先获得的是一台web服务器的webshell或者反弹shell,如果权限比较低,则需要进行权限提升:后续需要对系统进行全面的分析,搞清楚系统的用途:如果目 ...

  3. 【C++】C++ 左值、右值、右值引用详解

    左值.右值 在C++11中所有的值必属于左值.右值两者之一,右值又可以细分为纯右值.将亡值.在C++11中可以取地址的.有名字的就是左值,反之,不能取地址的.没有名字的就是右值(将亡值或纯右值).举个 ...

  4. spring boot允许跨域(CORS)的配置

    添加@Configuration配置类即可. @Configuration public class WebMvcConfig extends WebMvcConfigurationSupport { ...

  5. 全新思维导图 XMind ZEN v10.0.0 中文破解版

    http://www.carrotchou.blog/20331.html 官网 https://www.xmind.cn/ 注意事项 破解版本已经去除了全部的官方试用版的限制,让大家可以像正版用户一 ...

  6. Thinkphp5 实现动态模板主题多个模板切换

    在项目开发过程中会遇到一个网站有不同风格,本文详细介绍Thinkphp5 实现模板主题多个模板切换 一.在Config中配置view_path模板路径代码如下 1 2 3 4 5 6 7 8 9 10 ...

  7. Performance-Schema

    https://yq.aliyun.com/articles/640181?spm=a2c4e.11153940.0.0.347359d3DAu7sW MySQL Performance-Schema ...

  8. 分布式事务二TCC

    分布式事务解决方案之TCC 4.1.什么是TCC事务 TCC是Try.Confirm.Cancel三个词语的缩写,TCC要求每个分支事务实现三个操作:预处理Try.确认Confirm.撤销Cancel ...

  9. c# 通过win32 api 得到指定Console application Content

    已知的问题: 1. 调试的时候会报IO 异常,非调试环境是正常的 2. Windows 应用程序才可以使用,可以用非windows应用程序包一层 using System; using System. ...

  10. MySQL慢查询参数

    开启mysql慢查询日志 修改/etc/mysql/my.cnf配置文件,添加: [mysqld]slow_query_log = onslow_query_log_file = /var/lib/m ...