Spaces:
Sleeping
Sleeping
Minor adjustments
Browse files
polars/03_loading_data.py
CHANGED
|
@@ -113,7 +113,7 @@ def _(mo):
|
|
| 113 |
@app.cell
|
| 114 |
def _(df, folder, lz, pl):
|
| 115 |
lz.sink_csv(folder / "data.csv") # Lazy API - Writing to a file
|
| 116 |
-
df.write_csv(folder / "data_no_head.csv", include_header=False, separator="
|
| 117 |
|
| 118 |
_ = pl.scan_csv(folder / "data.csv") # Lazy API - Reading from a file
|
| 119 |
_ = pl.read_csv(folder / "data_no_head.csv", has_header=False, separator=";") # Eager API - Reading from a file
|
|
@@ -136,7 +136,7 @@ def _(mo):
|
|
| 136 |
|
| 137 |
Polars supports Lists with variable length, Arrays with fixed length, and Structs with well defined fields, but not mappings with arbitrary keys.
|
| 138 |
|
| 139 |
-
You might want to transform data
|
| 140 |
"""
|
| 141 |
)
|
| 142 |
return
|
|
@@ -152,8 +152,8 @@ def _(df, folder, lz, pl):
|
|
| 152 |
_ = pl.read_ndjson(folder / "data.ndjson") # Eager API - Reading from a file
|
| 153 |
|
| 154 |
# Normal JSON
|
| 155 |
-
df.write_json(folder / "
|
| 156 |
-
_ = pl.read_json(folder / "
|
| 157 |
|
| 158 |
# Note that there are no Lazy methods for normal JSON files,
|
| 159 |
# either use NDJSON instead or use `lz.collect().write_json()` to collect into memory before writing, and `pl.read_json().lazy()` to read into memory before operating in lazy mode
|
|
@@ -166,7 +166,7 @@ def _(mo):
|
|
| 166 |
r"""
|
| 167 |
## Databases
|
| 168 |
|
| 169 |
-
Polars doesn't supports any _directly_, but rather uses other libraries as Engines. Reading and writing to databases does not supports Lazy execution, but you may pass an SQL Query for the database to pre-filter the data before reaches polars. See the [User Guide](https://docs.pola.rs/user-guide/io/database) for more details.
|
| 170 |
|
| 171 |
Using the Arrow Database Connectivity SQLite support as an example:
|
| 172 |
"""
|
|
|
|
| 113 |
@app.cell
|
| 114 |
def _(df, folder, lz, pl):
|
| 115 |
lz.sink_csv(folder / "data.csv") # Lazy API - Writing to a file
|
| 116 |
+
df.write_csv(folder / "data_no_head.csv", include_header=False, separator=";") # Eager API - Writing to a file
|
| 117 |
|
| 118 |
_ = pl.scan_csv(folder / "data.csv") # Lazy API - Reading from a file
|
| 119 |
_ = pl.read_csv(folder / "data_no_head.csv", has_header=False, separator=";") # Eager API - Reading from a file
|
|
|
|
| 136 |
|
| 137 |
Polars supports Lists with variable length, Arrays with fixed length, and Structs with well defined fields, but not mappings with arbitrary keys.
|
| 138 |
|
| 139 |
+
You might want to transform data by unnesting structs and exploding lists after loading from complex JSON files.
|
| 140 |
"""
|
| 141 |
)
|
| 142 |
return
|
|
|
|
| 152 |
_ = pl.read_ndjson(folder / "data.ndjson") # Eager API - Reading from a file
|
| 153 |
|
| 154 |
# Normal JSON
|
| 155 |
+
df.write_json(folder / "data.json") # Eager API - Writing to a file
|
| 156 |
+
_ = pl.read_json(folder / "data.json") # Eager API - Reading from a file
|
| 157 |
|
| 158 |
# Note that there are no Lazy methods for normal JSON files,
|
| 159 |
# either use NDJSON instead or use `lz.collect().write_json()` to collect into memory before writing, and `pl.read_json().lazy()` to read into memory before operating in lazy mode
|
|
|
|
| 166 |
r"""
|
| 167 |
## Databases
|
| 168 |
|
| 169 |
+
Polars doesn't supports any databases _directly_, but rather uses other libraries as Engines. Reading and writing to databases does not supports Lazy execution, but you may pass an SQL Query for the database to pre-filter the data before reaches polars. See the [User Guide](https://docs.pola.rs/user-guide/io/database) for more details.
|
| 170 |
|
| 171 |
Using the Arrow Database Connectivity SQLite support as an example:
|
| 172 |
"""
|