2020-10-19 21:08:55

This commit is contained in:
wizardforcel
2020-10-19 21:08:55 +08:00
parent 7f63048035
commit ab0caba1f0
140 changed files with 3982 additions and 3982 deletions

View File

@@ -2,7 +2,7 @@
In [1]:
```
```py
import numpy as np
import pandas as pd
@@ -12,7 +12,7 @@ import pandas as pd
作为一维结构,它的索引叫做 `index`,基本调用方法为
```
```py
s = pd.Series(data, index=index)
```
@@ -30,7 +30,7 @@ s = pd.Series(data, index=index)
In [2]:
```
```py
s = pd.Series(np.random.randn(5), index=["a", "b", "c", "d", "e"])
s
@@ -39,7 +39,7 @@ s
Out[2]:
```
```py
a -0.032806
b 0.050207
c -1.909697
@@ -52,14 +52,14 @@ dtype: float64
In [3]:
```
```py
s.index
```
Out[3]:
```
```py
Index([u'a', u'b', u'c', u'd', u'e'], dtype='object')
```
@@ -67,14 +67,14 @@ Index([u'a', u'b', u'c', u'd', u'e'], dtype='object')
In [4]:
```
```py
pd.Series(np.random.randn(5))
```
Out[4]:
```
```py
0 -0.376233
1 -0.474349
2 1.660590
@@ -89,7 +89,7 @@ dtype: float64
In [5]:
```
```py
d = {'a' : 0., 'b' : 1., 'c' : 2.}
pd.Series(d)
@@ -98,7 +98,7 @@ pd.Series(d)
Out[5]:
```
```py
a 0
b 1
c 2
@@ -109,14 +109,14 @@ dtype: float64
In [6]:
```
```py
pd.Series(d, index=['b', 'd', 'a'])
```
Out[6]:
```
```py
b 1
d NaN
a 0
@@ -129,14 +129,14 @@ dtype: float64
In [7]:
```
```py
pd.Series(5., index=['a', 'b', 'c', 'd', 'e'])
```
Out[7]:
```
```py
a 5
b 5
c 5
@@ -149,14 +149,14 @@ dtype: float64
In [8]:
```
```py
s
```
Out[8]:
```
```py
a -0.032806
b 0.050207
c -1.909697
@@ -169,14 +169,14 @@ dtype: float64
In [9]:
```
```py
s[0]
```
Out[9]:
```
```py
-0.032806330572971713
```
@@ -184,14 +184,14 @@ Out[9]:
In [10]:
```
```py
s[:3]
```
Out[10]:
```
```py
a -0.032806
b 0.050207
c -1.909697
@@ -202,14 +202,14 @@ dtype: float64
In [11]:
```
```py
s[s > s.median()]
```
Out[11]:
```
```py
a -0.032806
b 0.050207
dtype: float64
@@ -219,14 +219,14 @@ dtype: float64
In [12]:
```
```py
s[[4, 3, 1]]
```
Out[12]:
```
```py
e -0.073793
d -1.127865
b 0.050207
@@ -237,14 +237,14 @@ dtype: float64
In [13]:
```
```py
np.exp(s)
```
Out[13]:
```
```py
a 0.967726
b 1.051488
c 0.148125
@@ -259,14 +259,14 @@ dtype: float64
In [14]:
```
```py
s["a"]
```
Out[14]:
```
```py
-0.032806330572971713
```
@@ -274,7 +274,7 @@ Out[14]:
In [15]:
```
```py
s["e"] = 12.
s
@@ -283,7 +283,7 @@ s
Out[15]:
```
```py
a -0.032806
b 0.050207
c -1.909697
@@ -296,27 +296,27 @@ dtype: float64
In [16]:
```
```py
"e" in s
```
Out[16]:
```
```py
True
```
In [17]:
```
```py
"f" in s
```
Out[17]:
```
```py
False
```
@@ -324,14 +324,14 @@ False
In [18]:
```
```py
s.get("f", np.nan)
```
Out[18]:
```
```py
nan
```
@@ -341,14 +341,14 @@ nan
In [19]:
```
```py
s + s
```
Out[19]:
```
```py
a -0.065613
b 0.100413
c -3.819395
@@ -359,14 +359,14 @@ dtype: float64
In [20]:
```
```py
s * 2
```
Out[20]:
```
```py
a -0.065613
b 0.100413
c -3.819395
@@ -379,14 +379,14 @@ dtype: float64
In [21]:
```
```py
s[1:] + s[:-1]
```
Out[21]:
```
```py
a NaN
b 0.100413
c -3.819395
@@ -403,7 +403,7 @@ dtype: float64
In [22]:
```
```py
s = pd.Series(np.random.randn(5), name='something')
s.name
@@ -411,6 +411,6 @@ s.name
Out[22]:
```
```py
'something'
```