程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

pandas. Series index

編輯:Python

pandas.Series Indexes

  • Location subscript
  • label
  • section
  • Boolean type

Location subscript

# Similar list 
import numpy
import pandas
s = pandas.Series(numpy.random.rand(5))
print(s[4])

label

import numpy
import pandas
s = pandas.Series(numpy.random.rand(3),index = ['a','b','c'])
print(s)
# Method is similar to subscript index , use [] Express , It says index, Be careful index Is string 
print(s["b"])
# If you need to select the value of multiple labels , use [[]] To express ( amount to [] Contains a list )
# The result of the multi label index is a new array 
sr = s[["b","a"]]
print(sr)

section

import numpy
import pandas
s1 = pandas.Series(numpy.random.rand(5))
s2 = pandas.Series(numpy.random.rand(3),index = ["a","b","c"])
print(s1[1:4]) # Subscript , Left closed right away 
print(s2["a":"c"]) # label , Left and right closed 
# If index Is the number , Priority defaults to subscript 
# Slice the subscript index , Same as list writing 
print(s2[:-1])
print(s2[::2]) # The stride is 2

Boolean type

import numpy
import pandas
s = pandas.Series(numpy.random.rand(3)*100)
s[4] = None # Add a null value 
print(s)
bs1 = s > 50 # Judge whether it is greater than 50
bs2 = s.isnull() # yes null
bs3 = s.notnull() # No null
print(bs1)
print(bs2)
print(bs3)
# After the array makes a judgment , What is returned is a new array of Boolean values 
# .isnull() / .notnull() Judge whether it is a null value 
# None For null ,NaN Represents the value in question , Both will be recognized as null 
# Boolean index method : use [ Judge the condition ] Express 
# The judgment condition can be a statement , Or a Boolean array 
print(s[s > 50])
print(s[bs3])

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved