https://www.cnblogs.com/songzhixue/p/11341440.html

实验数据

import pandas as pd
import numpy as np
s = pd.Series(data=[1,2,3,4,np.NaN,np.NaN],index=["a","b","c","d","e","f"])
print(type(s))
s[[True,True,False,False,True,True]]
s[["a","b"]]

#result

<class 'pandas.core.series.Series'>

Out[18]:

a    1.0
b    2.0
dtype: float64

若采用s['a','b']形式则会报错

TypeError: 'tuple' object cannot be interpreted as an integer

改成s[['a','b']]则正常返回说明series后跟的数据类型不能是元组形式的,要么一个中括号[]里面一个列名或索引值,要么后面2个中括号[[]],里面是多个列值

#结论

可见s类型是series的,那么series()在选择数据时候,后面参数是什么类型的要么标量一个嵌套[],要么2层[[]],里面参数是列名的列表

比如上例

s["a"]则可以答案为

1.0

进一步查看官方API如下

pandas.Series

class pandas.Series(data=Noneindex=Nonedtype=Nonename=Nonecopy=Falsefastpath=False)[source]

One-dimensional ndarray with axis labels (including time series).

Labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Statistical methods from ndarray have been overridden to automatically exclude missing data (currently represented as NaN).

Operations between Series (+, -, /, , *) align values based on their associated index values– they need not be the same length. The result index will be the sorted union of the two indexes.

Parameters

data array-like, Iterable, dict, or scalar value

Contains data stored in Series.

Changed in version 0.23.0: If data is a dict, argument order is maintained for Python 3.6 and later.

indexarray-like or Index (1d)

Values must be hashable and have the same length as data. Non-unique index values are allowed. Will default to RangeIndex (0, 1, 2, …, n) if not provided. If both a dict and index sequence are used, the index will override the keys found in the dict.

dtypestr, numpy.dtype, or ExtensionDtype, optional

Data type for the output Series. If not specified, this will be inferred from data. See the user guide for more usages.

namestr, optional

The name to give to the Series.

copybool, default False

Copy input data.

#########################################################

series对象支持查询操作

Series对象支持查询方式:
    位置下标
    标签索引
    切片索引
    布尔型索引

from pandas import Series
import pandas as pd

series1 = Series([10, 20, 30, 40], index=list('abcd'))

# 通过位置查询
series1[2]
# 通过标签索引查询
series1['b']
# 查询多个元素
series1[[0, 2, 3]]
series1[['a', 'c', 'd']]
# 切片
series1[1:3]
series1['b':'d']
# 布尔索引
series1[series1 > 20]

引自

https://blog.csdn.net/qq_39161737/article/details/78866191

官方API用法如下

  • df[col]:根据列名,并以Series的形式返回列
  • df[[col1, col2]]:以DataFrame形式返回多列
  • 引自
  • https://www.jianshu.com/p/a77b0bc736f2/

pandas.series的数据定位为什么用两个左中括号[[相关推荐

  1. pandas.Series.str.extract 正则提取数据

    pandas.Series.str.extract ¶ Series.str.extract(self,pat,flags = 0,expand = True )[来源] 提取的正则表达式捕获组拍作为 ...

  2. pandas中的数据对象Series

    pandas 的数据对象 Series 概要 用pandas 有一段时间,很少去总结,这篇文章 简单总结一些 pandas 中series 的一些常用方法,如果有更多的需要,可以查询官方文档. ser ...

  3. pandas中使用rolling.corr函数计算两个时间序列数据列之间的滚动相关性(Rolling correlations)、例如,计算两种商品销售额之间的3个月的滚动相关性

    pandas中使用rolling.corr函数计算两个时间序列数据列之间的滚动相关性(Rolling correlations).例如,计算两种商品销售额之间的3个月的滚动相关性 目录

  4. pandas使用query函数删除dataframe中两个数据列加和小于某一特定值的数据行(removing rows based on multiple dataframe column value

    pandas使用query函数删除dataframe中两个数据列加和小于某一特定值的数据行(removing rows based on multiple dataframe column value ...

  5. Seaborn可视化使用relplot函数可视化数据长度不同的时间序列实战:two Pandas Series of different lengths

    Seaborn可视化使用relplot函数可视化数据长度不同的时间序列实战:two Pandas Series of different lengths 目录

  6. [pandas基础]Pandas Series和Pandas DataFrame基础操作

    目录 Series基础 创建Series 通过索引获取数据 指定Series的索引值 根据索引值读取数据 使用key/value对象(类似字典)来创建Seires DataFrame基础 使用列表创建 ...

  7. pandas.DataFrame——pd数据框的简单认识、存csv文件

    接着前天的豆瓣书单信息爬取,这一篇文章看一下利用pandas完成对数据的存储. 回想一下我们当时在最后得到了六个列表:img_urls, titles, ratings, authors, detai ...

  8. 技术图文:Numpy 一维数组 VS. Pandas Series

    背景 Numpy 提供的最重要的数据结构是 ndarray,它是 Python 中 list 的扩展. Pandas 提供了两种非常重要的数据结构 Series和DataFrame. Numpy 中的 ...

  9. Pandas处理时序数据(初学者必会)!

    ↑↑↑关注后"星标"Datawhale每日干货 & 每月组队学习,不错过Datawhale干货 作者:耿远昊,Datawhale成员,华东师范大学 时序数据是指时间序列数据 ...

最新文章

  1. jQuery 图片高亮显示
  2. Java构造函数的使用_java中构造函数的使用方法
  3. 反射型 DDoS 攻击的原理和防范措施
  4. Computer:现代计算机操作系统的四大基本特性(并发/共享/虚拟/异步)
  5. [工具]-C语言实现:生成一个全是0x0的二进制文件
  6. ElementUI中el-upload中怎样限制上传文件的格式
  7. windows主机防护
  8. 平面上有两个圆相交,求两个圆相交部分的面积
  9. 《C语言编程魔法书:基于C11标准》——1.3 主流C语言编译器介绍
  10. arcgis分隔图层重复出文件_已知坐标点txt文件在ArcGIS中转换成shp数据的两种方法...
  11. java for循环的这种写法怎么理解:for (; ; ) {},
  12. SpringCloud 入门教程(一): 服务注册
  13. mha数据备份_MHA学习笔记
  14. 如何将卷积神经网络中的全连接层变成卷积层
  15. 文件和目录属性ls which alias
  16. 使用Excel2016求解运筹学线性规划
  17. (JavaScript案例)可拖动的模态框
  18. 河南省第九届ACM程序设计大赛总结
  19. 基于MATLAB的光纤通信仿真
  20. Qt 之 QSS(白色靓丽)

热门文章

  1. 使用 python 的单人AI 扫雷游戏
  2. matlab图像中心坐标的确定,已知散点图中各点的坐标,如何确定散点图的中心点坐标?Matlab? 爱问知识人...
  3. netstat 查看mysql_CentOS 使用netstat察看mysql端口和连接
  4. c++读取文本文件里的指定位置的字符_利用FSO对象向文本文件中写入信息
  5. datatable 汇总_【2019 版】中国石油大学(北京)计算机考研信息、资料汇总
  6. php swfupload handlers.js,swfupload使用代码说明
  7. python的pandas_python之pandas(一)
  8. httpclient 调取接口_使用HttpClient调用接口的实例讲解
  9. win7如何启动计算机,win7开机启动项怎么设置 电脑开机启动项在哪里设置
  10. LeetCode(7.整数反转)JAVA