Browse Source

Pandas

pull/135/merge
Jure Šorn 2 months ago
parent
commit
a821b2b55b
3 changed files with 133 additions and 128 deletions
  1. 84
      README.md
  2. 88
      index.html
  3. 89
      parse.js

84
README.md

@ -3231,7 +3231,7 @@ plt.show() # Displays the plot. Also plt.sav
**Table with labeled rows and columns.**
```python
>>> l = pd.DataFrame([[1, 2], [3, 4]], index=['a', 'b'], columns=['x', 'y']); l
>>> df = pd.DataFrame([[1, 2], [3, 4]], index=['a', 'b'], columns=['x', 'y']); df
x y
a 1 2
b 3 4
@ -3251,7 +3251,7 @@ b 3 4
```python
<S/DF> = <DF>[col_key/s] # Or: <DF>.<col_key>
<DF> = <DF>[row_bools] # Keeps rows as specified by bools.
<DF> = <DF>[<S_of_bools>] # Filters rows. For example `df[df.x > 1]`.
<DF> = <DF>[<DF_of_bools>] # Assigns NaN to items that are False in bools.
```
@ -3270,7 +3270,7 @@ b 3 4
```python
<DF> = <DF>.head/tail/sample(<int>) # Returns first, last, or random n rows.
<DF> = <DF>.describe() # Describes columns. Also info(), corr(), shape.
<DF> = <DF>.query('<query>') # Filters rows with e.g. 'col_1 == val_1 and …'.
<DF> = <DF>.query('<query>') # Filters rows. For example `df.query('x > 1')`.
```
```python
@ -3280,37 +3280,37 @@ plt.show() # Displays the plot. Also plt.sav
#### DataFrame — Merge, Join, Concat:
```python
>>> r = pd.DataFrame([[4, 5], [6, 7]], index=['b', 'c'], columns=['y', 'z']); r
>>> df_2 = pd.DataFrame([[4, 5], [6, 7]], index=['b', 'c'], columns=['y', 'z']); df_2
y z
b 4 5
c 6 7
```
```text
+------------------------+---------------+------------+------------+--------------------------+
| | 'outer' | 'inner' | 'left' | Description |
+------------------------+---------------+------------+------------+--------------------------+
| l.merge(r, on='y', | x y z | x y z | x y z | Merges on column if 'on' |
| how=…) | 0 1 2 . | 3 4 5 | 1 2 . | or 'left/right_on' are |
| | 1 3 4 5 | | 3 4 5 | set, else on shared cols.|
| | 2 . 6 7 | | | Uses 'inner' by default. |
+------------------------+---------------+------------+------------+--------------------------+
| l.join(r, lsuffix='l', | x yl yr z | | x yl yr z | Merges on row keys. |
| rsuffix='r', | a 1 2 . . | x yl yr z | 1 2 . . | Uses 'left' by default. |
| how=…) | b 3 4 4 5 | 3 4 4 5 | 3 4 4 5 | If r is a Series, it is |
| | c . . 6 7 | | | treated as a column. |
+------------------------+---------------+------------+------------+--------------------------+
| pd.concat([l, r], | x y z | y | | Adds rows at the bottom. |
| axis=0, | a 1 2 . | 2 | | Uses 'outer' by default. |
| join=…) | b 3 4 . | 4 | | A Series is treated as a |
| | b . 4 5 | 4 | | column. To add a row use |
| | c . 6 7 | 6 | | pd.concat([l, DF([s])]). |
+------------------------+---------------+------------+------------+--------------------------+
| pd.concat([l, r], | x y y z | | | Adds columns at the |
| axis=1, | a 1 2 . . | x y y z | | right end. Uses 'outer' |
| join=…) | b 3 4 4 5 | 3 4 4 5 | | by default. A Series is |
| | c . . 6 7 | | | treated as a column. |
+------------------------+---------------+------------+------------+--------------------------+
+-----------------------+---------------+------------+------------+---------------------------+
| | 'outer' | 'inner' | 'left' | Description |
+-----------------------+---------------+------------+------------+---------------------------+
| df.merge(df_2, | x y z | x y z | x y z | Merges on column if 'on' |
| on='y', | 0 1 2 . | 3 4 5 | 1 2 . | or 'left/right_on' are |
| how=…) | 1 3 4 5 | | 3 4 5 | set, else on shared cols. |
| | 2 . 6 7 | | | Uses 'inner' by default. |
+-----------------------+---------------+------------+------------+---------------------------+
| df.join(df_2, | x yl yr z | | x yl yr z | Merges on row keys. |
| lsuffix='l', | a 1 2 . . | x yl yr z | 1 2 . . | Uses 'left' by default. |
| rsuffix='r', | b 3 4 4 5 | 3 4 4 5 | 3 4 4 5 | If r is a Series, it is |
| how=…) | c . . 6 7 | | | treated as a column. |
+-----------------------+---------------+------------+------------+---------------------------+
| pd.concat([df, df_2], | x y z | y | | Adds rows at the bottom. |
| axis=0, | a 1 2 . | 2 | | Uses 'outer' by default. |
| join=…) | b 3 4 . | 4 | | A Series is treated as a |
| | b . 4 5 | 4 | | column. To add a row use |
| | c . 6 7 | 6 | | pd.concat([df, DF([s])]). |
+-----------------------+---------------+------------+------------+---------------------------+
| pd.concat([df, df_2], | x y y z | | | Adds columns at the |
| axis=1, | a 1 2 . . | x y y z | | right end. Uses 'outer' |
| join=…) | b 3 4 4 5 | 3 4 4 5 | | by default. A Series is |
| | c . . 6 7 | | | treated as a column. |
+-----------------------+---------------+------------+------------+---------------------------+
```
#### DataFrame — Aggregate, Transform, Map:
@ -3321,23 +3321,23 @@ c 6 7
```
```text
+----------------+---------------+---------------+---------------+
| | 'sum' | ['sum'] | {'x': 'sum'} |
+----------------+---------------+---------------+---------------+
| l.apply(…) | x 4 | x y | x 4 |
| l.agg(…) | y 6 | sum 4 6 | |
+----------------+---------------+---------------+---------------+
+-----------------+---------------+---------------+---------------+
| | 'sum' | ['sum'] | {'x': 'sum'} |
+-----------------+---------------+---------------+---------------+
| df.apply(…) | x 4 | x y | x 4 |
| df.agg(…) | y 6 | sum 4 6 | |
+-----------------+---------------+---------------+---------------+
```
```text
+----------------+---------------+---------------+---------------+
| | 'rank' | ['rank'] | {'x': 'rank'} |
+----------------+---------------+---------------+---------------+
| l.apply(…) | | x y | |
| l.agg(…) | x y | rank rank | x |
| l.transform(…) | a 1.0 1.0 | a 1.0 1.0 | a 1.0 |
| | b 2.0 2.0 | b 2.0 2.0 | b 2.0 |
+----------------+---------------+---------------+---------------+
+-----------------+---------------+---------------+---------------+
| | 'rank' | ['rank'] | {'x': 'rank'} |
+-----------------+---------------+---------------+---------------+
| df.apply(…) | | x y | |
| df.agg(…) | x y | rank rank | x |
| df.transform(…) | a 1.0 1.0 | a 1.0 1.0 | a 1.0 |
| | b 2.0 2.0 | b 2.0 2.0 | b 2.0 |
+-----------------+---------------+---------------+---------------+
```
* **All methods operate on columns by default. Pass `'axis=1'` to process the rows instead.**
* **Fifth result's columns are indexed with a multi-index. This means we need a tuple of column keys to specify a column: `'<DF>.loc[row_key, (col_key_1, col_key_2)]'`.**

88
index.html

@ -55,7 +55,7 @@
<body>
<header>
<aside>December 1, 2024</aside>
<aside>December 3, 2024</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</header>
@ -2631,7 +2631,7 @@ plt.show() <span class="hljs-comment"># Disp
<li><strong>Methods ffill(), interpolate(), fillna() and dropna() accept <code class="python hljs"><span class="hljs-string">'inplace=True'</span></code>.</strong></li>
<li><strong>Last result has a multi-index. Use <code class="python hljs"><span class="hljs-string">'&lt;S&gt;[key_1, key_2]'</span></code> to get its values.</strong></li>
</ul>
<div><h3 id="dataframe">DataFrame</h3><p><strong>Table with labeled rows and columns.</strong></p><pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>l = pd.DataFrame([[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>], [<span class="hljs-number">3</span>, <span class="hljs-number">4</span>]], index=[<span class="hljs-string">'a'</span>, <span class="hljs-string">'b'</span>], columns=[<span class="hljs-string">'x'</span>, <span class="hljs-string">'y'</span>]); l
<div><h3 id="dataframe">DataFrame</h3><p><strong>Table with labeled rows and columns.</strong></p><pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>df = pd.DataFrame([[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>], [<span class="hljs-number">3</span>, <span class="hljs-number">4</span>]], index=[<span class="hljs-string">'a'</span>, <span class="hljs-string">'b'</span>], columns=[<span class="hljs-string">'x'</span>, <span class="hljs-string">'y'</span>]); df
x y
a <span class="hljs-number">1</span> <span class="hljs-number">2</span>
b <span class="hljs-number">3</span> <span class="hljs-number">4</span>
@ -2647,7 +2647,7 @@ b <span class="hljs-number">3</span> <span class="hljs-number">4</span>
&lt;DF&gt; = &lt;DF&gt;.loc[row_bools, col_bools] <span class="hljs-comment"># Or: &lt;DF&gt;.iloc[row_bools, col_bools]</span>
</code></pre>
<pre><code class="python language-python hljs">&lt;S/DF&gt; = &lt;DF&gt;[col_key/s] <span class="hljs-comment"># Or: &lt;DF&gt;.&lt;col_key&gt;</span>
&lt;DF&gt; = &lt;DF&gt;[row_bools] <span class="hljs-comment"># Keeps rows as specified by bools.</span>
&lt;DF&gt; = &lt;DF&gt;[&lt;S_of_bools&gt;] <span class="hljs-comment"># Filters rows. For example `df[df.x &gt; 1]`.</span>
&lt;DF&gt; = &lt;DF&gt;[&lt;DF_of_bools&gt;] <span class="hljs-comment"># Assigns NaN to items that are False in bools.</span>
</code></pre>
<pre><code class="python language-python hljs">&lt;DF&gt; = &lt;DF&gt; &gt; &lt;el/S/DF&gt; <span class="hljs-comment"># Returns DF of bools. S is treated as a row.</span>
@ -2660,62 +2660,62 @@ b <span class="hljs-number">3</span> <span class="hljs-number">4</span>
</code></pre>
<pre><code class="python language-python hljs">&lt;DF&gt; = &lt;DF&gt;.head/tail/sample(&lt;int&gt;) <span class="hljs-comment"># Returns first, last, or random n rows.</span>
&lt;DF&gt; = &lt;DF&gt;.describe() <span class="hljs-comment"># Describes columns. Also info(), corr(), shape.</span>
&lt;DF&gt; = &lt;DF&gt;.query(<span class="hljs-string">'&lt;query&gt;'</span>) <span class="hljs-comment"># Filters rows with e.g. 'col_1 == val_1 and …'.</span>
&lt;DF&gt; = &lt;DF&gt;.query(<span class="hljs-string">'&lt;query&gt;'</span>) <span class="hljs-comment"># Filters rows. For example `df.query('x &gt; 1')`.</span>
</code></pre>
<pre><code class="python language-python hljs">&lt;DF&gt;.plot.line/area/bar/scatter(x=col_key, …) <span class="hljs-comment"># `y=col_key/s`. Also hist/box(by=col_key).</span>
plt.show() <span class="hljs-comment"># Displays the plot. Also plt.savefig(&lt;path&gt;).</span>
</code></pre>
<div><h4 id="dataframemergejoinconcat">DataFrame — Merge, Join, Concat:</h4><pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>r = pd.DataFrame([[<span class="hljs-number">4</span>, <span class="hljs-number">5</span>], [<span class="hljs-number">6</span>, <span class="hljs-number">7</span>]], index=[<span class="hljs-string">'b'</span>, <span class="hljs-string">'c'</span>], columns=[<span class="hljs-string">'y'</span>, <span class="hljs-string">'z'</span>]); r
<div><h4 id="dataframemergejoinconcat">DataFrame — Merge, Join, Concat:</h4><pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>df_2 = pd.DataFrame([[<span class="hljs-number">4</span>, <span class="hljs-number">5</span>], [<span class="hljs-number">6</span>, <span class="hljs-number">7</span>]], index=[<span class="hljs-string">'b'</span>, <span class="hljs-string">'c'</span>], columns=[<span class="hljs-string">'y'</span>, <span class="hljs-string">'z'</span>]); df_2
y z
b <span class="hljs-number">4</span> <span class="hljs-number">5</span>
c <span class="hljs-number">6</span> <span class="hljs-number">7</span>
</code></pre></div>
<pre><code class="python hljs">┏━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━┓
<span class="hljs-string">'outer'</span><span class="hljs-string">'inner'</span><span class="hljs-string">'left'</span> │ Description ┃
┠───────────────────────┼───────────────┼────────────┼────────────┼──────────────────────────┨
l.merge(r, on=<span class="hljs-string">'y'</span>, │ x y z │ x y z │ x y z │ Merges on column if <span class="hljs-string">'on'</span>
how=…)<span class="hljs-number">0</span> <span class="hljs-number">1</span> <span class="hljs-number">2</span> . │ <span class="hljs-number">3</span> <span class="hljs-number">4</span> <span class="hljs-number">5</span><span class="hljs-number">1</span> <span class="hljs-number">2</span> . │ or <span class="hljs-string">'left/right_on'</span> are ┃
<span class="hljs-number">1</span> <span class="hljs-number">3</span> <span class="hljs-number">4</span> <span class="hljs-number">5</span> │ │ <span class="hljs-number">3</span> <span class="hljs-number">4</span> <span class="hljs-number">5</span> │ set, else on shared cols.┃
<span class="hljs-number">2</span> . <span class="hljs-number">6</span> <span class="hljs-number">7</span> │ │ │ Uses <span class="hljs-string">'inner'</span> by default. ┃
┠───────────────────────┼───────────────┼────────────┼────────────┼──────────────────────────┨
l.join(r, lsuffix=<span class="hljs-string">'l'</span>, │ x yl yr z │ │ x yl yr z │ Merges on row keys. ┃
rsuffix=<span class="hljs-string">'r'</span>, │ a <span class="hljs-number">1</span> <span class="hljs-number">2</span> . . │ x yl yr z │ <span class="hljs-number">1</span> <span class="hljs-number">2</span> . . │ Uses <span class="hljs-string">'left'</span> by default. ┃
how=…) │ b <span class="hljs-number">3</span> <span class="hljs-number">4</span> <span class="hljs-number">4</span> <span class="hljs-number">5</span><span class="hljs-number">3</span> <span class="hljs-number">4</span> <span class="hljs-number">4</span> <span class="hljs-number">5</span><span class="hljs-number">3</span> <span class="hljs-number">4</span> <span class="hljs-number">4</span> <span class="hljs-number">5</span> │ If r is a Series, it is ┃
│ c . . <span class="hljs-number">6</span> <span class="hljs-number">7</span> │ │ │ treated as a column. ┃
┠───────────────────────┼───────────────┼────────────┼────────────┼──────────────────────────┨
┃ pd.concat([l, r], │ x y z │ y │ │ Adds rows at the bottom. ┃
┃ axis=<span class="hljs-number">0</span>, │ a <span class="hljs-number">1</span> <span class="hljs-number">2</span> . │ <span class="hljs-number">2</span> │ │ Uses <span class="hljs-string">'outer'</span> by default. ┃
┃ join=…) │ b <span class="hljs-number">3</span> <span class="hljs-number">4</span> . │ <span class="hljs-number">4</span> │ │ A Series is treated as a ┃
│ b . <span class="hljs-number">4</span> <span class="hljs-number">5</span><span class="hljs-number">4</span> │ │ column. To add a row use ┃
│ c . <span class="hljs-number">6</span> <span class="hljs-number">7</span><span class="hljs-number">6</span> │ │ pd.concat([l, DF([s])]). ┃
┠───────────────────────┼───────────────┼────────────┼────────────┼──────────────────────────┨
┃ pd.concat([l, r], │ x y y z │ │ │ Adds columns at the ┃
┃ axis=<span class="hljs-number">1</span>, │ a <span class="hljs-number">1</span> <span class="hljs-number">2</span> . . │ x y y z │ │ right end. Uses <span class="hljs-string">'outer'</span>
┃ join=…) │ b <span class="hljs-number">3</span> <span class="hljs-number">4</span> <span class="hljs-number">4</span> <span class="hljs-number">5</span><span class="hljs-number">3</span> <span class="hljs-number">4</span> <span class="hljs-number">4</span> <span class="hljs-number">5</span> │ │ by default. A Series is ┃
│ c . . <span class="hljs-number">6</span> <span class="hljs-number">7</span> │ │ │ treated as a column. ┃
┗━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━┛
<pre><code class="python hljs">┏━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ │ <span class="hljs-string">'outer'</span><span class="hljs-string">'inner'</span><span class="hljs-string">'left'</span> │ Description
┠───────────────────────┼───────────────┼────────────┼────────────┼──────────────────────────┨
df.merge(df_2, │ x y z │ x y z │ x y z │ Merges on column if 'on' ┃
on=<span class="hljs-string">'y'</span>,<span class="hljs-number">0</span> <span class="hljs-number">1</span> <span class="hljs-number">2</span> . │ <span class="hljs-number">3</span> <span class="hljs-number">4</span> <span class="hljs-number">5</span><span class="hljs-number">1</span> <span class="hljs-number">2</span> . │ or 'left/right_on' are
how=…)<span class="hljs-number">1</span> <span class="hljs-number">3</span> <span class="hljs-number">4</span> <span class="hljs-number">5</span> │ │ <span class="hljs-number">3</span> <span class="hljs-number">4</span> <span class="hljs-number">5</span> │ set, else on shared cols.
┃ │ <span class="hljs-number">2</span> . <span class="hljs-number">6</span> <span class="hljs-number">7</span> │ │ │ Uses <span class="hljs-string">'inner'</span> by default.
┠───────────────────────┼───────────────┼────────────┼────────────┼──────────────────────────┨
df.join(df_2, │ x yl yr z │ │ x yl yr z │ Merges on row keys.
lsuffix=<span class="hljs-string">'l'</span>, │ a <span class="hljs-number">1</span> <span class="hljs-number">2</span> . . │ x yl yr z │ <span class="hljs-number">1</span> <span class="hljs-number">2</span> . . │ Uses <span class="hljs-string">'left'</span> by default.
rsuffix=<span class="hljs-string">'r'</span>, │ b <span class="hljs-number">3</span> <span class="hljs-number">4</span> <span class="hljs-number">4</span> <span class="hljs-number">5</span><span class="hljs-number">3</span> <span class="hljs-number">4</span> <span class="hljs-number">4</span> <span class="hljs-number">5</span><span class="hljs-number">3</span> <span class="hljs-number">4</span> <span class="hljs-number">4</span> <span class="hljs-number">5</span> │ If r is a Series, it is
how=…) │ c . . <span class="hljs-number">6</span> <span class="hljs-number">7</span> │ │ │ treated as a column.
┠───────────────────────┼───────────────┼────────────┼────────────┼──────────────────────────┨
┃ pd.concat([df, df_2], │ x y z │ y │ │ Adds rows at the bottom.
┃ axis=<span class="hljs-number">0</span>, │ a <span class="hljs-number">1</span> <span class="hljs-number">2</span> . │ <span class="hljs-number">2</span> │ │ Uses <span class="hljs-string">'outer'</span> by default.
┃ join=…) │ b <span class="hljs-number">3</span> <span class="hljs-number">4</span> . │ <span class="hljs-number">4</span> │ │ A Series is treated as a
┃ │ b . <span class="hljs-number">4</span> <span class="hljs-number">5</span><span class="hljs-number">4</span> │ │ column. To add a row use
┃ │ c . <span class="hljs-number">6</span> <span class="hljs-number">7</span><span class="hljs-number">6</span> │ │ pd.concat([df, DF([s])]). ┃
┠───────────────────────┼───────────────┼────────────┼────────────┼──────────────────────────┨
┃ pd.concat([df, df_2], │ x y y z │ │ │ Adds columns at the
┃ axis=<span class="hljs-number">1</span>, │ a <span class="hljs-number">1</span> <span class="hljs-number">2</span> . . │ x y y z │ │ right end. Uses <span class="hljs-string">'outer'</span>
┃ join=…) │ b <span class="hljs-number">3</span> <span class="hljs-number">4</span> <span class="hljs-number">4</span> <span class="hljs-number">5</span><span class="hljs-number">3</span> <span class="hljs-number">4</span> <span class="hljs-number">4</span> <span class="hljs-number">5</span> │ │ by default. A Series is
┃ │ c . . <span class="hljs-number">6</span> <span class="hljs-number">7</span> │ │ │ treated as a column.
┗━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━┛
</code></pre>
<div><h4 id="dataframeaggregatetransformmap">DataFrame — Aggregate, Transform, Map:</h4><pre><code class="python language-python hljs">&lt;S&gt; = &lt;DF&gt;.sum/max/mean/idxmax/all() <span class="hljs-comment"># Or: &lt;DF&gt;.apply/agg(lambda &lt;S&gt;: &lt;el&gt;)</span>
&lt;DF&gt; = &lt;DF&gt;.rank/diff/cumsum/ffill/interpo…() <span class="hljs-comment"># Or: &lt;DF&gt;.apply/agg/transform(lambda &lt;S&gt;: &lt;S&gt;)</span>
&lt;DF&gt; = &lt;DF&gt;.isna/fillna/isin([&lt;el/coll&gt;]) <span class="hljs-comment"># Or: &lt;DF&gt;.applymap(lambda &lt;el&gt;: &lt;el&gt;)</span>
</code></pre></div>
<pre><code class="python hljs">┏━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┓
┃ │ <span class="hljs-string">'sum'</span> │ [<span class="hljs-string">'sum'</span>] │ {<span class="hljs-string">'x'</span>: <span class="hljs-string">'sum'</span>} ┃
┠────────────────┼───────────────┼───────────────┼───────────────┨
l.apply(…) │ x <span class="hljs-number">4</span> │ x y │ x <span class="hljs-number">4</span>
l.agg(…) │ y <span class="hljs-number">6</span> │ sum <span class="hljs-number">4</span> <span class="hljs-number">6</span> │ ┃
┗━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┛
<pre><code class="python hljs">┏━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┓
<span class="hljs-string">'sum'</span> │ [<span class="hljs-string">'sum'</span>] │ {<span class="hljs-string">'x'</span>: <span class="hljs-string">'sum'</span>} ┃
┠────────────────┼───────────────┼───────────────┼───────────────┨
df.apply(…) │ x <span class="hljs-number">4</span> │ x y │ x <span class="hljs-number">4</span>
df.agg(…) │ y <span class="hljs-number">6</span> │ sum <span class="hljs-number">4</span> <span class="hljs-number">6</span> │ ┃
┗━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┛
┏━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┓
┃ │ <span class="hljs-string">'rank'</span> │ [<span class="hljs-string">'rank'</span>] │ {<span class="hljs-string">'x'</span>: <span class="hljs-string">'rank'</span>} ┃
┠────────────────┼───────────────┼───────────────┼───────────────┨
l.apply(…) │ │ x y │ ┃
l.agg(…) │ x y │ rank rank │ x ┃
l.transform(…) │ a <span class="hljs-number">1.0</span> <span class="hljs-number">1.0</span> │ a <span class="hljs-number">1.0</span> <span class="hljs-number">1.0</span> │ a <span class="hljs-number">1.0</span>
┃ │ b <span class="hljs-number">2.0</span> <span class="hljs-number">2.0</span> │ b <span class="hljs-number">2.0</span> <span class="hljs-number">2.0</span> │ b <span class="hljs-number">2.0</span>
┗━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┛
┏━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┓
<span class="hljs-string">'rank'</span> │ [<span class="hljs-string">'rank'</span>] │ {<span class="hljs-string">'x'</span>: <span class="hljs-string">'rank'</span>} ┃
┠────────────────┼───────────────┼───────────────┼───────────────┨
df.apply(…) │ │ x y │ ┃
df.agg(…) │ x y │ rank rank │ x ┃
df.transform(…) │ a <span class="hljs-number">1.0</span> <span class="hljs-number">1.0</span> │ a <span class="hljs-number">1.0</span> <span class="hljs-number">1.0</span> │ a <span class="hljs-number">1.0</span>
│ b <span class="hljs-number">2.0</span> <span class="hljs-number">2.0</span> │ b <span class="hljs-number">2.0</span> <span class="hljs-number">2.0</span> │ b <span class="hljs-number">2.0</span>
┗━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┛
</code></pre>
<ul>
@ -2924,7 +2924,7 @@ $ deactivate <span class="hljs-comment"># Deactivates the active
<footer>
<aside>December 1, 2024</aside>
<aside>December 3, 2024</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</footer>

89
parse.js

@ -599,56 +599,57 @@ const DIAGRAM_14_A =
"| | 'rank' | ['rank'] | {'r': 'rank'} |";
const DIAGRAM_15_A =
'+------------------------+---------------+------------+------------+--------------------------+';
'+-----------------------+---------------+------------+------------+---------------------------+';
const DIAGRAM_15_B =
"┏━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n" +
"┃ │ 'outer' │ 'inner' │ 'left' │ Description ┃\n" +
"┠────────────────────────┼───────────────┼────────────┼────────────┼──────────────────────────┨\n" +
"┃ l.merge(r, on='y', │ x y z │ x y z │ x y z │ Merges on column if 'on' ┃\n" +
"┃ how=…) │ 0 1 2 . │ 3 4 5 │ 1 2 . │ or 'left/right_on' are ┃\n" +
"┃ │ 1 3 4 5 │ │ 3 4 5 │ set, else on shared cols.┃\n" +
"┃ │ 2 . 6 7 │ │ │ Uses 'inner' by default. ┃\n" +
"┠────────────────────────┼───────────────┼────────────┼────────────┼──────────────────────────┨\n" +
"┃ l.join(r, lsuffix='l', │ x yl yr z │ │ x yl yr z │ Merges on row keys. ┃\n" +
"┃ rsuffix='r', │ a 1 2 . . │ x yl yr z │ 1 2 . . │ Uses 'left' by default. ┃\n" +
"┃ how=…) │ b 3 4 4 5 │ 3 4 4 5 │ 3 4 4 5 │ If r is a Series, it is ┃\n" +
"┃ │ c . . 6 7 │ │ │ treated as a column. ┃\n" +
"┠────────────────────────┼───────────────┼────────────┼────────────┼──────────────────────────┨\n" +
"┃ pd.concat([l, r], │ x y z │ y │ │ Adds rows at the bottom. ┃\n" +
"┃ axis=0, │ a 1 2 . │ 2 │ │ Uses 'outer' by default. ┃\n" +
"┃ join=…) │ b 3 4 . │ 4 │ │ A Series is treated as a ┃\n" +
"┃ │ b . 4 5 │ 4 │ │ column. To add a row use ┃\n" +
"┃ │ c . 6 7 │ 6 │ │ pd.concat([l, DF([s])]). ┃\n" +
"┠────────────────────────┼───────────────┼────────────┼────────────┼──────────────────────────┨\n" +
"┃ pd.concat([l, r], │ x y y z │ │ │ Adds columns at the ┃\n" +
"┃ axis=1, │ a 1 2 . . │ x y y z │ │ right end. Uses 'outer' ┃\n" +
"┃ join=…) │ b 3 4 4 5 │ 3 4 4 5 │ │ by default. A Series is ┃\n" +
"┃ │ c . . 6 7 │ │ │ treated as a column. ┃\n" +
"┗━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n";
"┏━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n" +
"┃ │ 'outer' │ 'inner' │ 'left' │ Description ┃\n" +
"┠───────────────────────┼───────────────┼────────────┼────────────┼───────────────────────────┨\n" +
"┃ df.merge(df_2, │ x y z │ x y z │ x y z │ Merges on column if 'on' ┃\n" +
"┃ on='y', │ 0 1 2 . │ 3 4 5 │ 1 2 . │ or 'left/right_on' are ┃\n" +
"┃ how=…) │ 1 3 4 5 │ │ 3 4 5 │ set, else on shared cols. ┃\n" +
"┃ │ 2 . 6 7 │ │ │ Uses 'inner' by default. ┃\n" +
"┠───────────────────────┼───────────────┼────────────┼────────────┼───────────────────────────┨\n" +
"┃ df.join(df_2, │ x yl yr z │ │ x yl yr z │ Merges on row keys. ┃\n" +
"┃ lsuffix='l', │ a 1 2 . . │ x yl yr z │ 1 2 . . │ Uses 'left' by default. ┃\n" +
"┃ rsuffix='r', │ b 3 4 4 5 │ 3 4 4 5 │ 3 4 4 5 │ If r is a Series, it is ┃\n" +
"┃ how=…) │ c . . 6 7 │ │ │ treated as a column. ┃\n" +
"┠───────────────────────┼───────────────┼────────────┼────────────┼───────────────────────────┨\n" +
"┃ pd.concat([df, df_2], │ x y z │ y │ │ Adds rows at the bottom. ┃\n" +
"┃ axis=0, │ a 1 2 . │ 2 │ │ Uses 'outer' by default. ┃\n" +
"┃ join=…) │ b 3 4 . │ 4 │ │ A Series is treated as a ┃\n" +
"┃ │ b . 4 5 │ 4 │ │ column. To add a row use ┃\n" +
"┃ │ c . 6 7 │ 6 │ │ pd.concat([df, DF([s])]). ┃\n" +
"┠───────────────────────┼───────────────┼────────────┼────────────┼───────────────────────────┨\n" +
"┃ pd.concat([df, df_2], │ x y y z │ │ │ Adds columns at the ┃\n" +
"┃ axis=1, │ a 1 2 . . │ x y y z │ │ right end. Uses 'outer' ┃\n" +
"┃ join=…) │ b 3 4 4 5 │ 3 4 4 5 │ │ by default. A Series is ┃\n" +
"┃ │ c . . 6 7 │ │ │ treated as a column. ┃\n" +
"┗━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n";
const DIAGRAM_16_A =
'| l.apply(…) | x 4 | x y | x 4 |';
'| df.apply(…) | x 4 | x y | x 4 |';
const DIAGRAM_16_B =
"┏━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┓\n" +
"┃ │ 'sum' │ ['sum'] │ {'x': 'sum'} ┃\n" +
"┠────────────────┼───────────────┼───────────────┼───────────────┨\n" +
"┃ l.apply(…) │ x 4 │ x y │ x 4 ┃\n" +
"┃ l.agg(…) │ y 6 │ sum 4 6 │ ┃\n" +
"┗━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┛\n" +
"┏━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┓\n" +
"┃ │ 'sum' │ ['sum'] │ {'x': 'sum'} ┃\n" +
"┠────────────────┼───────────────┼───────────────┼───────────────┨\n" +
"┃ df.apply(…) │ x 4 │ x y │ x 4 ┃\n" +
"┃ df.agg(…) │ y 6 │ sum 4 6 │ ┃\n" +
"┗━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┛\n" +
"\n" +
"┏━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┓\n" +
"┃ │ 'rank' │ ['rank'] │ {'x': 'rank'} ┃\n" +
"┠────────────────┼───────────────┼───────────────┼───────────────┨\n" +
"┃ l.apply(…) │ │ x y │ ┃\n" +
"┃ l.agg(…) │ x y │ rank rank │ x ┃\n" +
"┃ l.transform(…) │ a 1.0 1.0 │ a 1.0 1.0 │ a 1.0 ┃\n" +
"┃ │ b 2.0 2.0 │ b 2.0 2.0 │ b 2.0 ┃\n" +
"┗━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┛\n";
"┏━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┓\n" +
"┃ │ 'rank' │ ['rank'] │ {'x': 'rank'} ┃\n" +
"┠────────────────┼───────────────┼───────────────┼───────────────┨\n" +
"┃ df.apply(…) │ │ x y │ ┃\n" +
"┃ df.agg(…) │ x y │ rank rank │ x ┃\n" +
"┃ df.transform(…) │ a 1.0 1.0 │ a 1.0 1.0 │ a 1.0 ┃\n" +
"┃ │ b 2.0 2.0 │ b 2.0 2.0 │ b 2.0 ┃\n" +
"┗━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┛\n";
const DIAGRAM_17_A =
"| | 'rank' | ['rank'] | {'x': 'rank'} |";
"| | 'rank' | ['rank'] | {'x': 'rank'} |";
const DIAGRAM_18_A =
'| gb.agg(…) | x y | | x y | |';
@ -897,7 +898,7 @@ function insertPageBreakBefore(an_id) {
}
function fixPandasDiagram() {
const diagram_15 = '┏━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━┓';
const diagram_15 = '┏━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━┓';
$(`code:contains(${diagram_15})`).find(".hljs-keyword:contains(and)").after("and");
$(`code:contains(${diagram_15})`).find(".hljs-keyword:contains(as)").after("as");
$(`code:contains(${diagram_15})`).find(".hljs-keyword:contains(is)").after("is");
@ -905,6 +906,10 @@ function fixPandasDiagram() {
$(`code:contains(${diagram_15})`).find(".hljs-keyword:contains(or)").after("or");
$(`code:contains(${diagram_15})`).find(".hljs-keyword:contains(else)").after("else");
$(`code:contains(${diagram_15})`).find(".hljs-keyword").remove();
$(`code:contains(${diagram_15})`).find(".hljs-string:contains(\'left/right_on\')").after("\'left/right_on\'");
$(`code:contains(${diagram_15})`).find(".hljs-string:contains(\'left/right_on\')").remove();
$(`code:contains(${diagram_15})`).find(".hljs-string:contains('on')").after("'on'");
$(`code:contains(${diagram_15})`).find(".hljs-string:contains('on')").remove();
}
function removePlotImages() {

Loading…
Cancel
Save