约定:
import pandas as pd
from pandas import Series,DataFrame
import numpy as np
se1=Series([4,7,-2,8])
se1
代码结果:
0 4
1 7
2 -2
3 8
dtype: int64
se2=Series([4,7,-2,8],index=['b','c','a','d'])
se2
代码结果:
b 4
c 7
a -2
d 8
dtype: int64
se1.values
代码结果:
array([ 4, 7, -2, 8], dtype=int64)
se1.index
代码结果:
RangeIndex(start=0, stop=4, step=1)
'b' in se2
代码结果:
True
list(se2)
代码结果:
[4, 7, -2, 8]
list(se2.iteritems())
代码结果:
[('b', 4), ('c', 7), ('a', -2), ('d', 8)]
dict={"red":100,"black":400,"green":300,"pink":900}
se3=Series(dict)
se3
代码结果:
black 400
green 300
pink 900
red 100
dtype: int64
se3
代码结果:
black 400
green 300
pink 900
red 100
dtype: int64
se3.name="values"
se3.index.name="color"
se3
代码结果:
color
black 400
green 300
pink 900
red 100
Name: values, dtype: int64
pd.isnull(se3)
代码结果:
purple False
brown False
glod False
blue False
Name: values, dtype: bool
pd.notnull(se3)
代码结果:
purple True
brown True
glod True
blue True
Name: values, dtype: bool
se3.isnull()
代码结果:
purple False
brown False
glod False
blue False
Name: values, dtype: bool
print("位置下标: ",se2[1])
print("标签下标: ",se2['c'])
代码结果:
位置下标: 7
标签下标: 7
se2
代码结果:
b 4
c 7
a -2
d 8
dtype: int64
se2[1:3]
代码结果:
c 7
a -2
dtype: int64
se2['b':'a']
代码结果:
b 4
c 7
a -2
dtype: int64
se2[[1,3,2]]
代码结果:
c 7
d 8
a -2
dtype: int64
se2[['a','b','c']]
代码结果:
a -2
b 4
c 7
dtype: int64
se4=Series(dict,index=["red","yellow","green","white","black","pink"])
se4
代码结果:
red 100.0
yellow NaN
green 300.0
white NaN
black 400.0
pink 900.0
dtype: float64
se4.index=["red","yellow","black","pink","green","white"]
se4
代码结果:
red 100.0
yellow NaN
black 300.0
pink NaN
green 400.0
white 900.0
dtype: float64
se2
代码结果:
b 4
c 7
a -2
d 8
dtype: int64
se2[se2>0]
代码结果:
b 4
c 7
d 8
dtype: int64
se2*2
代码结果:
b 8
c 14
a -4
d 16
dtype: int64
np.exp(se2)
代码结果:
b 54.598150
c 1096.633158
a 0.135335
d 2980.957987
dtype: float64
se2+se3
代码结果:
a NaN
b NaN
blue NaN
brown NaN
c NaN
d NaN
glod NaN
purple NaN
dtype: float64
谢谢大家的浏览,
希望我的努力对您有帮助,
共勉!