|
7 | 7 | "source": [ |
8 | 8 | "# Pandas\n", |
9 | 9 | "\n", |
10 | | - "Copyright 2023 Marco A. Lopez-Sanchez. \n", |
| 10 | + "Copyright 2023-2025 Marco A. Lopez-Sanchez. \n", |
11 | 11 | "Content under [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) License](http://creativecommons.org/licenses/by-nc-sa/4.0/).\n", |
12 | 12 | "\n", |
13 | 13 | "> **Goal**: \n", |
|
990 | 990 | "\n", |
991 | 991 | "> 👉 When subsetting a DataFrame it is good practice to use the ``.copy()`` method because what you get by default is a view of the original DataFrame and all modifications you make to this new DataFrame will affect the original one. This is: \n", |
992 | 992 | ">```python\n", |
993 | | - ">new_df = df.loc[['CO_eclogite', 'CO_granulite', 'CO_pyroxenite']] ❌ \n", |
994 | | - ">new_df = df.loc[['CO_eclogite', 'CO_granulite', 'CO_pyroxenite']].copy() ✅ \n", |
| 993 | + ">new_df = df.loc[:, ['CO_eclogite', 'CO_granulite', 'CO_pyroxenite']] ❌ \n", |
| 994 | + ">new_df = df.loc[:, ['CO_eclogite', 'CO_granulite', 'CO_pyroxenite']].copy() ✅ \n", |
995 | 995 | ">```\n", |
996 | 996 | "> ⚠️ Beware! Contrary to regular Python or Numpy, the Pandas ``.loc`` method **includes** the index stop point so that ``df.loc[0:2]`` is equivalent to ``array[0:3]``" |
997 | 997 | ] |
|
2019 | 2019 | "name": "stdout", |
2020 | 2020 | "output_type": "stream", |
2021 | 2021 | "text": [ |
2022 | | - "Notebook tested in 2024-04-10 using:\n", |
2023 | | - "Python 3.11.8 | packaged by Anaconda, Inc. | (main, Feb 26 2024, 21:34:05) [MSC v.1916 64 bit (AMD64)]\n", |
2024 | | - "Pandas 2.1.4\n" |
| 2022 | + "Notebook tested in 2025-01-22 using:\n", |
| 2023 | + "Python 3.12.4 | packaged by Anaconda, Inc. | (main, Jun 18 2024, 15:03:56) [MSC v.1929 64 bit (AMD64)]\n", |
| 2024 | + "Pandas 2.2.3\n" |
2025 | 2025 | ] |
2026 | 2026 | } |
2027 | 2027 | ], |
|
2038 | 2038 | ], |
2039 | 2039 | "metadata": { |
2040 | 2040 | "kernelspec": { |
2041 | | - "display_name": "Python 3 (ipykernel)", |
| 2041 | + "display_name": "main", |
2042 | 2042 | "language": "python", |
2043 | 2043 | "name": "python3" |
2044 | 2044 | }, |
|
2052 | 2052 | "name": "python", |
2053 | 2053 | "nbconvert_exporter": "python", |
2054 | 2054 | "pygments_lexer": "ipython3", |
2055 | | - "version": "3.11.8" |
2056 | | - }, |
2057 | | - "vscode": { |
2058 | | - "interpreter": { |
2059 | | - "hash": "073408933f31e8ac7f6b4bf29a6f48e1a2f613d7d5b6e5c6c58fd8fdc8389e42" |
2060 | | - } |
| 2055 | + "version": "3.12.4" |
2061 | 2056 | } |
2062 | 2057 | }, |
2063 | 2058 | "nbformat": 4, |
|
0 commit comments