import pandas as pd
import numpy as np
s1 = pd.Series([1,-2,2.3,'hq'])
print(s1)
0 1
1 -2
2 2.3
3 hq
dtype: object
type(s1)
pandas.core.series.Series
s2 = pd.Series([1,-2,2.3,'hq'],index = ["a","b","c","d"])
print(s2)
a 1
b -2
c 2.3
d hq
dtype: object
s3 = pd.Series((1,2,3,4,'hq'))
print(s3)
0 1
1 2
2 3
3 4
4 hq
dtype: object
s4 = pd.Series(np.array([1,2,4,7.1]))
print(s4)
0 1.0
1 2.0
2 4.0
3 7.1
dtype: float64
mydict = {"red":2000,"blue":1000,"yellow":500}
ss = pd.Series(mydict)
print(ss)
red 2000
blue 1000
yellow 500
dtype: int64
print(s1[3])
hq
print(s2["c"])
2.3
va1 = s1.values
print(va1)
[1 -2 2.3 'hq']
in1 = s1.index
print(in1)
RangeIndex(start=0, stop=4, step=1)
in2 = list(in1)
print(in2)
[0, 1, 2, 3]
s5 = pd.Series([1,2,2,3,"hq","hq","he"])
s51 = s5.unique()
print(s51)
[1 2 3 'hq' 'he']
s52 = s5.isin([0,"he"])
print(s52)
0 False
1 False
2 False
3 False
4 False
5 False
6 True
dtype: bool
s53 = s5.value_counts()
print(s53)
2 2
hq 2
he 1
1 1
3 1
dtype: int64
s54 = s5.value_counts("hq")
print(s54)
2 0.285714
hq 0.285714
he 0.142857
1 0.142857
3 0.142857
dtype: float64
ss1 = pd.Series([10,"hq",60,np.nan,20])
tt1 = ss1[~ss1.isnull()]
print(tt1)
0 10
1 hq
2 60
4 20
dtype: object
tt2 = ss1[ss1.notnull()]
print(tt2)
0 10
1 hq
2 60
4 20
dtype: object
tt3 = ss1.dropna()
print(tt3)
0 10
1 hq
2 60
4 20
dtype: object
s22 = s2[["a","d"]]
print(s22)
a 1
d hq
dtype: object
s11 = s1[0:2]
print(s11)
0 1
1 -2
dtype: object
s12 = s1[[0,2,3]]
print(s12)
0 1
2 2.3
3 hq
dtype: object
s41 = s4[s4 > 2]
print(s41)
2 4.0
3 7.1
dtype: float64
print("-" * 25)
-------------------------
s = pd.Series([1,2,4,5,6,7,8,9,10])
su = s.sum()
print(su)
52
sm = s.mean()
print(sm)
5.777777777777778
ss = s.std()
print(ss)
3.0731814857642954
smx = s.max()
print(smx)
10
smi = s.min()
print(smi)
1
|