This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new b2146b8889 docs(bindings/python): ipynb examples for polars and pandas 
(#4368)
b2146b8889 is described below

commit b2146b88893f8104835018a128342d946de1eb79
Author: Weijie Guo <[email protected]>
AuthorDate: Fri Mar 15 19:00:23 2024 +0800

    docs(bindings/python): ipynb examples for polars and pandas (#4368)
---
 bindings/python/examples/pandas.ipynb | 43 +++++++++++++++++++++++++++++++
 bindings/python/examples/polars.ipynb | 48 +++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+)

diff --git a/bindings/python/examples/pandas.ipynb 
b/bindings/python/examples/pandas.ipynb
new file mode 100644
index 0000000000..d13c933c02
--- /dev/null
+++ b/bindings/python/examples/pandas.ipynb
@@ -0,0 +1,43 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Install the opendal and pandas\n",
+    "!pip install opendal, pandas"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import opendal\n",
+    "import pandas as pd\n",
+    "\n",
+    "# Init an operator.\n",
+    "op = opendal.Operator(\"fs\", root=\"/tmp\")\n",
+    "\n",
+    "# Create and write a csv file\n",
+    "op.write(\"test.csv\", b\"name,age\\nAlice,25\\nBob,30\\nCharlie,35\")\n",
+    "\n",
+    "# Open and read the DataFrame from the file.\n",
+    "with op.open(\"test123.csv\", mode=\"rb\") as file:\n",
+    "    read_df = pd.read_csv(file)\n",
+    "    print(f\"read_df: {read_df}\")"
+   ]
+  }
+ ],
+ "metadata": {
+  "language_info": {
+   "name": "python"
+  },
+  "orig_nbformat": 4
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/bindings/python/examples/polars.ipynb 
b/bindings/python/examples/polars.ipynb
new file mode 100644
index 0000000000..0fe871320e
--- /dev/null
+++ b/bindings/python/examples/polars.ipynb
@@ -0,0 +1,48 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Install the opendal and polars\n",
+    "!pip install opendal, polars"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import opendal\n",
+    "import polars as pl\n",
+    "\n",
+    "# Init an operator.\n",
+    "op = opendal.Operator(\"fs\", root=\"/tmp\")\n",
+    "\n",
+    "# Create a DataFrame.\n",
+    "df = pl.DataFrame({\"name\": [\"Alice\", \"Bob\"], \"age\": [20, 30]})\n",
+    "print(f\"df: {df}\")\n",
+    "\n",
+    "# Open and write the DataFrame to the file.\n",
+    "with op.open(\"test.csv\", mode=\"wb\") as file:\n",
+    "    df.write_csv(file)\n",
+    "\n",
+    "# Open and read the DataFrame from the file.\n",
+    "with op.open(\"test.csv\", mode=\"rb\") as file:\n",
+    "    read_df = pl.read_csv(file)\n",
+    "    print(f\"read_df: {read_df}\")"
+   ]
+  }
+ ],
+ "metadata": {
+  "language_info": {
+   "name": "python"
+  },
+  "orig_nbformat": 4
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

Reply via email to