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
@@ -26,7 +26,7 @@ import pandas as pd
In [2]:
```
```py
d = {'one' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])}
@@ -36,7 +36,7 @@ d = {'one' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
In [3]:
```
```py
df = pd.DataFrame(d)
df
@@ -56,7 +56,7 @@ Out[3]:
In [4]:
```
```py
pd.DataFrame(d, index=['d', 'b', 'a'])
```
@@ -73,7 +73,7 @@ Out[4]:
In [5]:
```
```py
pd.DataFrame(d, index=['d', 'b', 'a'], columns=['two', 'three'])
```
@@ -90,27 +90,27 @@ Out[5]:
In [6]:
```
```py
df.index
```
Out[6]:
```
```py
Index([u'a', u'b', u'c', u'd'], dtype='object')
```
In [7]:
```
```py
df.columns
```
Out[7]:
```
```py
Index([u'one', u'two'], dtype='object')
```
@@ -120,7 +120,7 @@ Index([u'one', u'two'], dtype='object')
In [8]:
```
```py
d = {'one' : [1., 2., 3., 4.],
'two' : [4., 3., 2., 1.]}
@@ -130,7 +130,7 @@ d = {'one' : [1., 2., 3., 4.],
In [9]:
```
```py
pd.DataFrame(d)
```
@@ -148,7 +148,7 @@ Out[9]:
In [10]:
```
```py
pd.DataFrame(d, index=['a', 'b', 'c', 'd'])
```
@@ -168,7 +168,7 @@ Out[10]:
In [11]:
```
```py
data = np.zeros((2,), dtype=[('A', 'i4'),('B', 'f4'),('C', 'a10')])
data[:] = [(1,2.,'Hello'), (2,3.,"World")]
@@ -178,7 +178,7 @@ data
Out[11]:
```
```py
array([(1, 2.0, 'Hello'), (2, 3.0, 'World')],
dtype=[('A', '<i4'), ('B', '<f4'), ('C', 'S10')])
```
@@ -187,7 +187,7 @@ array([(1, 2.0, 'Hello'), (2, 3.0, 'World')],
In [12]:
```
```py
pd.DataFrame(data)
```
@@ -201,7 +201,7 @@ Out[12]:
In [13]:
```
```py
pd.DataFrame(data, index=['first', 'second'])
```
@@ -215,7 +215,7 @@ Out[13]:
In [14]:
```
```py
pd.DataFrame(data, columns=['C', 'A', 'B'])
```
@@ -233,7 +233,7 @@ Out[14]:
In [15]:
```
```py
data2 = [{'a': 1, 'b': 2}, {'a': 5, 'b': 10, 'c': 20}]
pd.DataFrame(data2)
@@ -249,7 +249,7 @@ Out[15]:
In [16]:
```
```py
pd.DataFrame(data2, index=['first', 'second'])
```
@@ -263,7 +263,7 @@ Out[16]:
In [17]:
```
```py
pd.DataFrame(data2, columns=['a', 'b'])
```
@@ -285,7 +285,7 @@ Out[17]:
In [18]:
```
```py
pd.DataFrame.from_records(data, index='C')
```
@@ -303,7 +303,7 @@ Out[18]:
In [19]:
```
```py
pd.DataFrame.from_items([('A', [1, 2, 3]), ('B', [4, 5, 6])])
```
@@ -322,14 +322,14 @@ Out[19]:
In [20]:
```
```py
df["one"]
```
Out[20]:
```
```py
a 1
b 2
c 3
@@ -341,7 +341,7 @@ Name: one, dtype: float64
In [21]:
```
```py
df['three'] = df['one'] * df['two']
df['flag'] = df['one'] > 2
@@ -363,7 +363,7 @@ Out[21]:
In [22]:
```
```py
del df["two"]
three = df.pop("three")
@@ -385,7 +385,7 @@ Out[22]:
In [23]:
```
```py
df['foo'] = 'bar'
df
@@ -405,7 +405,7 @@ Out[23]:
In [24]:
```
```py
df['one_trunc'] = df['one'][:2]
df
@@ -427,7 +427,7 @@ Out[24]:
In [25]:
```
```py
df.insert(1, 'bar', df['one'])
df
@@ -447,7 +447,7 @@ Out[25]:
In [28]:
```
```py
df.assign(test=df["one"] + df["bar"])
```