import pandas as pd
import numpy as np
s = pd.Series(np.random.randn(5), index=["a","b","c","d","e"])
s
a 0.365672
b -0.259483
c -0.404180
d -0.310866
e -0.256827
dtype: float64
s.index
Index(['a', 'b', 'c', 'd', 'e'], dtype='object')
s = pd.Series(np.random.randn(5))
s
0 -0.788125
1 -1.291259
2 0.014401
3 -1.244146
4 0.712529
dtype: float64
d = {
"a":0, "b":1, "d":3}
s = pd.Series(d, index=list("abcd"))
s
a 0.0
b 1.0
c NaN
d 3.0
dtype: float64
s = pd.Series(5, index=list("abcd"))
s
a 5
b 5
c 5
d 5
dtype: int64
s = pd.Series(np.random.randn(5))
s
0 -1.065998
1 -0.459723
2 -1.676296
3 0.169716
4 -0.402579
dtype: float64
s[0]
-1.0659982426438701
s[:3]
0 -1.065998
1 -0.459723
2 -1.676296
dtype: float64
s[2:5]
2 -1.676296
3 0.169716
4 -0.402579
dtype: float64
s[[1,3,4]]
1 -0.459723
3 0.169716
4 -0.402579
dtype: float64
np.sin(s)
0 -0.875272
1 -0.443700
2 -0.994440
3 0.168902
4 -0.391792
dtype: float64
s = pd.Series(np.random.randn(5),index=["a","b","c","d","e"])
s
a -0.013971
b -0.301559
c 1.540719
d -0.158722
e 0.504045
dtype: float64
s["a"]
-0.013970643761681575
s["b"]=3
s
a -0.013971
b 3.000000
c 1.540719
d -0.158722
e 0.504045
dtype: float64
s["g"]=100
s
a -0.013971
b 3.000000
c 1.540719
d -0.158722
e 0.504045
g 100.000000
dtype: float64
print(s.get("f"))
None
s1 = pd.Series(np.random.randn(3), index=["a","c","e"])
s2 = pd.Series(np.random.randn(3), index=["a","d","e"])
print("{0}\n\n{1}".format(s1,s2))
a 0.002169
c 0.799666
e -0.138819
dtype: float64
a 1.147344
d -1.013595
e -1.466308
dtype: float64
s1 + s2
a 1.149512
c NaN
d NaN
e -1.605126
dtype: float64
d = {
"one": pd.Series([1,2,3],index=["a","b","c"]),
"two": pd.Series([1,2,3,4], index=["a","b","c","d"])}
df = pd.DataFrame(d)
df