Browse Source

Pandas

pull/192/head
Jure Šorn 5 months ago
parent
commit
1a02f13142
2 changed files with 8 additions and 8 deletions
  1. 6
      README.md
  2. 10
      index.html

6
README.md

@ -3166,7 +3166,6 @@ Name: a, dtype: int64
```python
<S> = pd.Series(<list>) # Creates index from list's indices.
<S> = pd.Series(<dict>) # Creates index from dictionary's keys.
<S> = pd.Series(<dict/Series>, index=<list>) # Only keeps items with keys specified in index.
```
```python
@ -3193,11 +3192,11 @@ Name: a, dtype: int64
```
```python
<S>.plot.line/area/bar/pie/hist() # Generates a plot. Accepts `title=<str>`.
plt.show() # Displays the plot. Also plt.savefig(<path>).
<S>.plot.line/area/bar/pie/hist() # Generates a plot. `plt.show()` displays it.
```
* **Indexing objects can't be tuples because `'obj[x, y]'` is converted to `'obj[(x, y)]'`!**
* **Pandas uses NumPy types like `'np.int64'`. Series is converted to `'float64'` if we assign np.nan to any item. Use `'<S>.astype(<str/type>)'` to get converted Series.**
* **Series will silently overflow if we run `'pd.Series([100], dtype="int8") + 100'`.**
#### Series — Aggregate, Transform, Map:
```python
@ -3225,6 +3224,7 @@ plt.show() # Displays the plot. Also plt.sav
+--------------+-------------+-------------+---------------+
```
* **Methods ffill(), interpolate(), fillna() and dropna() accept `'inplace=True'`.**
* **Agg/transform() pass Series to functions that raise Type/Value/AttrError on single item.**
* **Last result has a multi-index. Use `'<S>[key_1, key_2]'` to get its values.**
### DataFrame

10
index.html

@ -55,7 +55,7 @@
<body>
<header>
<aside>December 3, 2024</aside>
<aside>December 4, 2024</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</header>
@ -2582,7 +2582,6 @@ Name: a, dtype: int64
<pre><code class="python language-python hljs">&lt;S&gt; = pd.Series(&lt;list&gt;) <span class="hljs-comment"># Creates index from list's indices.</span>
&lt;S&gt; = pd.Series(&lt;dict&gt;) <span class="hljs-comment"># Creates index from dictionary's keys.</span>
&lt;S&gt; = pd.Series(&lt;dict/Series&gt;, index=&lt;list&gt;) <span class="hljs-comment"># Only keeps items with keys specified in index.</span>
</code></pre>
<pre><code class="python language-python hljs">&lt;el&gt; = &lt;S&gt;.loc[key] <span class="hljs-comment"># Or: &lt;S&gt;.iloc[i]</span>
&lt;S&gt; = &lt;S&gt;.loc[coll_of_keys] <span class="hljs-comment"># Or: &lt;S&gt;.iloc[coll_of_i]</span>
@ -2599,12 +2598,12 @@ Name: a, dtype: int64
&lt;S&gt; = &lt;S&gt;.combine_first(&lt;S&gt;) <span class="hljs-comment"># Adds items that are not yet present.</span>
&lt;S&gt;.update(&lt;S&gt;) <span class="hljs-comment"># Updates items that are already present.</span>
</code></pre>
<pre><code class="python language-python hljs">&lt;S&gt;.plot.line/area/bar/pie/hist() <span class="hljs-comment"># Generates a plot. Accepts `title=&lt;str&gt;`.</span>
plt.show() <span class="hljs-comment"># Displays the plot. Also plt.savefig(&lt;path&gt;).</span>
<pre><code class="python language-python hljs">&lt;S&gt;.plot.line/area/bar/pie/hist() <span class="hljs-comment"># Generates a plot. `plt.show()` displays it.</span>
</code></pre>
<ul>
<li><strong>Indexing objects can't be tuples because <code class="python hljs"><span class="hljs-string">'obj[x, y]'</span></code> is converted to <code class="python hljs"><span class="hljs-string">'obj[(x, y)]'</span></code>!</strong></li>
<li><strong>Pandas uses NumPy types like <code class="python hljs"><span class="hljs-string">'np.int64'</span></code>. Series is converted to <code class="python hljs"><span class="hljs-string">'float64'</span></code> if we assign np.nan to any item. Use <code class="python hljs"><span class="hljs-string">'&lt;S&gt;.astype(&lt;str/type&gt;)'</span></code> to get converted Series.</strong></li>
<li><strong>Series will silently overflow if we run <code class="python hljs"><span class="hljs-string">'pd.Series([100], dtype="int8") + 100'</span></code>.</strong></li>
</ul>
<div><h4 id="seriesaggregatetransformmap">Series — Aggregate, Transform, Map:</h4><pre><code class="python language-python hljs">&lt;el&gt; = &lt;S&gt;.sum/max/mean/idxmax/all() <span class="hljs-comment"># Or: &lt;S&gt;.agg(lambda &lt;S&gt;: &lt;el&gt;)</span>
&lt;S&gt; = &lt;S&gt;.rank/diff/cumsum/ffill/interpol…() <span class="hljs-comment"># Or: &lt;S&gt;.agg/transform(lambda &lt;S&gt;: &lt;S&gt;)</span>
@ -2629,6 +2628,7 @@ plt.show() <span class="hljs-comment"># Disp
<ul>
<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>Agg/transform() pass Series to functions that raise Type/Value/AttrError on single item.</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>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
@ -2924,7 +2924,7 @@ $ deactivate <span class="hljs-comment"># Deactivates the active
<footer>
<aside>December 3, 2024</aside>
<aside>December 4, 2024</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</footer>

|||||||
100:0
Loading…
Cancel
Save