Skip to content

Commit 51d1127

Browse files
committed
Pandas
1 parent 380ec20 commit 51d1127

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3352,15 +3352,16 @@ c 6 7
33523352

33533353
#### DataFrame — Encode, Decode:
33543354
```python
3355-
<DF> = pd.read_json/html('<str/path/url>') # Run `$ pip3 install beautifulsoup4 lxml`.
3356-
<DF> = pd.read_csv('<path/url>') # `header/index_col/dtype/usecols/…=<obj>`.
3357-
<DF> = pd.read_pickle/excel('<path/url>') # Use `sheet_name=None` to get all Excel sheets.
3358-
<DF> = pd.read_sql('<table/query>', <conn.>) # SQLite3/SQLAlchemy connection (see #SQLite).
3355+
<DF> = pd.read_json/pickle(<path/url/file>) # Also accepts io.StringIO/BytesIO(<str/bytes>).
3356+
<DF> = pd.read_csv(<path/url/file>) # `header/index_col/dtype/usecols/…=<obj>`.
3357+
<DF> = pd.read_excel(<path/url/file>) # `sheet_name=None` returns dict of all sheets.
3358+
<DF> = pd.read_sql('<table/query>', <conn>) # SQLite3/SQLAlchemy connection (see #SQLite).
3359+
<list> = pd.read_html(<path/url/file>) # Run `$ pip3 install beautifulsoup4 lxml`.
33593360
```
33603361

33613362
```python
33623363
<dict> = <DF>.to_dict('d/l/s/…') # Returns columns as dicts, lists or series.
3363-
<str> = <DF>.to_json/html/csv/latex() # Saves output to a file if path is passed.
3364+
<str> = <DF>.to_json/csv/html/latex() # Saves output to a file if path is passed.
33643365
<DF>.to_pickle/excel(<path>) # Run `$ pip3 install "pandas[excel]" odfpy`.
33653366
<DF>.to_sql('<table_name>', <connection>) # Also `if_exists='fail/replace/append'`.
33663367
```
@@ -3373,8 +3374,7 @@ c 6 7
33733374

33743375
```python
33753376
<GB> = <DF>.groupby(col_key/s) # Splits DF into groups based on passed column.
3376-
<DF> = <GB>.apply(<func>) # Maps each group. Func can return DF, S or el.
3377-
<DF> = <GB>.filter(<func>) # Drops a group if function returns False.
3377+
<DF> = <GB>.apply/filter(<func>) # Filter drops a group if func returns False.
33783378
<DF> = <GB>.get_group(<el>) # Selects a group by grouping column's value.
33793379
<S> = <GB>.size() # S of group sizes. Same keys as get_group().
33803380
<GB> = <GB>[col_key] # Single column GB. All operations return S.

index.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
<body>
5757
<header>
58-
<aside>December 19, 2024</aside>
58+
<aside>December 20, 2024</aside>
5959
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
6060
</header>
6161

@@ -2729,14 +2729,15 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
27292729
&lt;DF&gt; = &lt;DF&gt;.pivot_table(index=col_key/s) <span class="hljs-comment"># `columns=key/s, values=key/s, aggfunc='mean'`.</span>
27302730
</code></pre></div>
27312731

2732-
<div><h4 id="dataframeencodedecode">DataFrame — Encode, Decode:</h4><pre><code class="python language-python hljs">&lt;DF&gt; = pd.read_json/html(<span class="hljs-string">'&lt;str/path/url&gt;'</span>) <span class="hljs-comment"># Run `$ pip3 install beautifulsoup4 lxml`.</span>
2733-
&lt;DF&gt; = pd.read_csv(<span class="hljs-string">'&lt;path/url&gt;'</span>) <span class="hljs-comment"># `header/index_col/dtype/usecols/…=&lt;obj&gt;`.</span>
2734-
&lt;DF&gt; = pd.read_pickle/excel(<span class="hljs-string">'&lt;path/url&gt;'</span>) <span class="hljs-comment"># Use `sheet_name=None` to get all Excel sheets.</span>
2735-
&lt;DF&gt; = pd.read_sql(<span class="hljs-string">'&lt;table/query&gt;'</span>, &lt;conn.&gt;) <span class="hljs-comment"># SQLite3/SQLAlchemy connection (see #SQLite).</span>
2732+
<div><h4 id="dataframeencodedecode">DataFrame — Encode, Decode:</h4><pre><code class="python language-python hljs">&lt;DF&gt; = pd.read_json/pickle(&lt;path/url/file&gt;) <span class="hljs-comment"># Also accepts io.StringIO/BytesIO(&lt;str/bytes&gt;).</span>
2733+
&lt;DF&gt; = pd.read_csv(&lt;path/url/file&gt;) <span class="hljs-comment"># `header/index_col/dtype/usecols/…=&lt;obj&gt;`.</span>
2734+
&lt;DF&gt; = pd.read_excel(&lt;path/url/file&gt;) <span class="hljs-comment"># `sheet_name=None` returns dict of all sheets.</span>
2735+
&lt;DF&gt; = pd.read_sql(<span class="hljs-string">'&lt;table/query&gt;'</span>, &lt;conn&gt;) <span class="hljs-comment"># SQLite3/SQLAlchemy connection (see #SQLite).</span>
2736+
&lt;list&gt; = pd.read_html(&lt;path/url/file&gt;) <span class="hljs-comment"># Run `$ pip3 install beautifulsoup4 lxml`.</span>
27362737
</code></pre></div>
27372738

27382739
<pre><code class="python language-python hljs">&lt;dict&gt; = &lt;DF&gt;.to_dict(<span class="hljs-string">'d/l/s/…'</span>) <span class="hljs-comment"># Returns columns as dicts, lists or series.</span>
2739-
&lt;str&gt; = &lt;DF&gt;.to_json/html/csv/latex() <span class="hljs-comment"># Saves output to a file if path is passed.</span>
2740+
&lt;str&gt; = &lt;DF&gt;.to_json/csv/html/latex() <span class="hljs-comment"># Saves output to a file if path is passed.</span>
27402741
&lt;DF&gt;.to_pickle/excel(&lt;path&gt;) <span class="hljs-comment"># Run `$ pip3 install "pandas[excel]" odfpy`.</span>
27412742
&lt;DF&gt;.to_sql(<span class="hljs-string">'&lt;table_name&gt;'</span>, &lt;connection&gt;) <span class="hljs-comment"># Also `if_exists='fail/replace/append'`.</span>
27422743
</code></pre>
@@ -2746,8 +2747,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
27462747
<li><strong>To get specific attributes from a series of Timestamps use <code class="python hljs"><span class="hljs-string">'&lt;S&gt;.dt.year/date/…'</span></code>.</strong></li>
27472748
</ul>
27482749
<div><h3 id="groupby">GroupBy</h3><p><strong>Object that groups together rows of a dataframe based on the value of the passed column.</strong></p><pre><code class="python language-python hljs">&lt;GB&gt; = &lt;DF&gt;.groupby(col_key/s) <span class="hljs-comment"># Splits DF into groups based on passed column.</span>
2749-
&lt;DF&gt; = &lt;GB&gt;.apply(&lt;func&gt;) <span class="hljs-comment"># Maps each group. Func can return DF, S or el.</span>
2750-
&lt;DF&gt; = &lt;GB&gt;.filter(&lt;func&gt;) <span class="hljs-comment"># Drops a group if function returns False.</span>
2750+
&lt;DF&gt; = &lt;GB&gt;.apply/filter(&lt;func&gt;) <span class="hljs-comment"># Filter drops a group if func returns False.</span>
27512751
&lt;DF&gt; = &lt;GB&gt;.get_group(&lt;el&gt;) <span class="hljs-comment"># Selects a group by grouping column's value.</span>
27522752
&lt;S&gt; = &lt;GB&gt;.size() <span class="hljs-comment"># S of group sizes. Same keys as get_group().</span>
27532753
&lt;GB&gt; = &lt;GB&gt;[col_key] <span class="hljs-comment"># Single column GB. All operations return S.</span>
@@ -2924,7 +2924,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
29242924

29252925

29262926
<footer>
2927-
<aside>December 19, 2024</aside>
2927+
<aside>December 20, 2024</aside>
29282928
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
29292929
</footer>
29302930

0 commit comments

Comments
 (0)