Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(python): Doc example for read_csv (#13161) #13545

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions py-polars/polars/io/csv/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,33 @@ def read_csv(
all data will be stored continuously in memory.
Set `rechunk=False` if you are benchmarking the csv-reader. A `rechunk` is
an expensive operation.

Examples
--------
>>> pl.read_csv("data.csv", separator="|") # doctest: +SKIP

Reproducible example using BytesIO object, parsing dates.

>>> import io # doctest: +SKIP
>>> source = io.BytesIO(
... (
... "ID,Name,Birthday\n"
... "1,Alice,1995-07-12\n"
... "2,Bob,1990-09-20\n"
... "3,Charlie,2002-03-08"
... ).encode()
... ) # doctest: +SKIP
>>> pl.read_csv(source, try_parse_dates=True) # doctest: +SKIP
shape: (3, 3)
┌─────┬─────────┬────────────┐
│ ID ┆ Name ┆ Birthday │
│ --- ┆ --- ┆ --- │
│ i64 ┆ str ┆ date │
╞═════╪═════════╪════════════╡
│ 1 ┆ Alice ┆ 1995-07-12 │
│ 2 ┆ Bob ┆ 1990-09-20 │
│ 3 ┆ Charlie ┆ 2002-03-08 │
└─────┴─────────┴────────────┘
"""
_check_arg_is_1byte("separator", separator, can_be_empty=False)
_check_arg_is_1byte("quote_char", quote_char, can_be_empty=True)
Expand Down