Skip to content

Commit 5ce9a27

Browse files
committed
docs: update fill_null documentation with detailed usage examples
1 parent b28756f commit 5ce9a27

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

docs/source/library-user-guide/using-the-dataframe-api.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,19 @@ async fn main() -> Result<()> {
198198
}
199199
```
200200

201-
[`custom_file_format.rs`]: https://github.com/apache/datafusion/blob/main/datafusion-examples/examples/custom_file_format.rs
201+
## Fill Null Values with DataFrame::fill_null
202202

203-
The output file will look like (Example Output):
203+
The `fill_null` method allows you to replace null values in specified columns with a provided value. When an empty list of columns is passed, the operation is applied to all columns. The method only fills if the given value can be cast to the column's data type.
204204

205-
```sql
206-
> select * from '../datafusion/core/example.parquet';
207-
+---+---+---+
208-
| a | b | c |
209-
+---+---+---+
210-
| 1 | 2 | 3 |
211-
+---+---+---+
205+
**Usage Example:**
206+
207+
```rust
208+
// Fill nulls in specific columns "a" and "c":
209+
let df = ctx.read_csv("tests/data/example.csv", CsvReadOptions::new()).await?;
210+
let df = df.fill_null(ScalarValue::from(0), vec!["a".to_owned(), "c".to_owned()])?;
211+
212+
// Fill nulls across all columns:
213+
let df = df.fill_null(ScalarValue::from(0), vec![])?;
212214
```
213215

214216
## Relationship between `LogicalPlan`s and `DataFrame`s

0 commit comments

Comments
 (0)