import numpy
import pandas
# Subscript indices / label index add value
s1 = pandas.Series(numpy.random.rand(5))
s2 = pandas.Series(numpy.random.rand(5), index = list('abcde'))
s1[5] = 100
s2["f"] = 100
print(s1)
print(s2)
# .append Method to add an array directly
# .append Method to generate a new array , Do not change the previous array
s3 = s1.append(s2)
print(s3)
drop: Delete
import numpy
import pandas
s = pandas.Series(numpy.random.rand(5), index = list('abcde'))
print(s)
s1 = s.drop("a")
print(s1)
# inplace: The return value after deleting the element , The default is False
s2 = s.drop(["b","c"],inplace = True)
# If inplace by True, The return value is None
print(s2)
modify
s = pandas.Series(numpy.random.rand(3),index = ['a','b','c'])
# Modify the index directly , Similar list
s['a'] = 100
s[['b','c']] = 200
print(s)
head / tail: View
import numpy
import pandas
s = pandas.Series(numpy.random.rand(15))
print(s.head(2)) # .head() Look at the header data , View by default 5 strip
print(s.tail()) # .tail() Check the tail data , View by default 5 strip
reindex: Re index
import numpy
import pandas
s = pandas.Series(numpy.random.rand(5),index = list("abcde"))
print(s)
# .reindex Will be reordered according to the new index , If the current index does not exist , Then the missing value is introduced
s2 = s.reindex(list("bcfea")) # .reindex() Also write a list in
# here 'f' Index does not exist , Therefore, the missing value introduced is NaN
print(s2)
# fill_value: Fill in the missing value
s3 = s.reindex(list("qwert"),fill_value = 0)
print(s3)
alignment
import numpy
import pandas
# Series It will be automatically aligned according to the label
s1 = pandas.Series(numpy.random.rand(3),index = ([" Love clothes "," Li Yi "," Meiqin "]))
s2 = pandas.Series(numpy.random.rand(2),index = ([" Meiqin "," Li Yi "]))
# index The order does not affect the numerical calculation , It will be calculated by label
# Null value and any value calculation result is still null
print(s1 + s2)