From 1a02f13142119e0f44809e13c0a9f4d6a1908203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Wed, 4 Dec 2024 05:58:37 +0100 Subject: [PATCH] Pandas --- README.md | 6 +++--- index.html | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4899da1..b5ef95e 100644 --- a/README.md +++ b/README.md @@ -3166,7 +3166,6 @@ Name: a, dtype: int64 ```python = pd.Series() # Creates index from list's indices. = pd.Series() # Creates index from dictionary's keys. - = pd.Series(, index=) # Only keeps items with keys specified in index. ``` ```python @@ -3193,11 +3192,11 @@ Name: a, dtype: int64 ``` ```python -.plot.line/area/bar/pie/hist() # Generates a plot. Accepts `title=`. -plt.show() # Displays the plot. Also plt.savefig(). +.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 `'.astype()'` 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 `'[key_1, key_2]'` to get its values.** ### DataFrame diff --git a/index.html b/index.html index 7ba2306..e6f46f4 100644 --- a/index.html +++ b/index.html @@ -55,7 +55,7 @@
- +
@@ -2582,7 +2582,6 @@ Name: a, dtype: int64
<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.
 
<el> = <S>.loc[key]                            # Or: <S>.iloc[i]
 <S>  = <S>.loc[coll_of_keys]                   # Or: <S>.iloc[coll_of_i]
@@ -2599,12 +2598,12 @@ Name: a, dtype: int64
 <S> = <S>.combine_first(<S>)                   # Adds items that are not yet present.
 <S>.update(<S>)                                # Updates items that are already present.
 
-
<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:

<el> = <S>.sum/max/mean/idxmax/all()           # Or: <S>.agg(lambda <S>: <el>)
 <S>  = <S>.rank/diff/cumsum/ffill/interpol…()  # Or: <S>.agg/transform(lambda <S>: <S>)
@@ -2629,6 +2628,7 @@ plt.show()                                     # Disp
 
 
  • 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

Table with labeled rows and columns.

>>> df = pd.DataFrame([[1, 2], [3, 4]], index=['a', 'b'], columns=['x', 'y']); df
@@ -2924,7 +2924,7 @@ $ deactivate                # Deactivates the active