Skip to content

Commit 1c03ba0

Browse files
committed
Avoid unnecessary decoding when reading into pandas
1 parent d224647 commit 1c03ba0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

docs/source/examples/Widget List.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@
10691069
"#=> b'This is the content of example.txt.\\n'\n",
10701070
"```\n",
10711071
"\n",
1072-
"If the file is a text file, you can get the contents as a string by decoding it:\n",
1072+
"If the file is a text file, you can get the contents as a string by [decoding it](https://docs.python.org/3/library/codecs.html):\n",
10731073
"\n",
10741074
"```python\n",
10751075
"import codecs\n",
@@ -1084,12 +1084,12 @@
10841084
" fp.write(uploaded_file[\"content\"])\n",
10851085
"```\n",
10861086
"\n",
1087-
"To convert the uploaded file into a Pandas dataframe, you need to convert it to a StringIO object:\n",
1087+
"To convert the uploaded file into a Pandas dataframe, you need to convert it to a [BytesIO object](https://docs.python.org/3/library/io.html#binary-i-o):\n",
10881088
"\n",
10891089
"```python\n",
10901090
"import io\n",
10911091
"import pandas as pd\n",
1092-
"pd.read_csv(io.StringIO(codecs.decode(uploaded_file[\"content\"], encoding=\"utf-8\")))\n",
1092+
"pd.read_csv(io.BytesIO(uploaded_file[\"content\"]))\n",
10931093
"```\n",
10941094
"\n",
10951095
"If the uploaded file is an image, you can visualize it with an [image](#Image) widget:\n",

0 commit comments

Comments
 (0)